--- title: "Update Data in Cache" url: https://docs.catalyst.zoho.com/en/sdk/java/v1/cloud-scale/cache/update-data-in-cache/ description: "This page describes the method to update data in the cache in your Java application with sample code snippets." last_updated: 2025-11-19T15:07:41Z service: Cloud Scale type: sdk related_links: - name: "Update Data in Cache - API" url: /en/api/code-reference/cloud-scale/cache/update-key-value/#UpdateKey-ValuePair - name: "Cache" url: /en/cloud-scale/help/cache/introduction --- # Update Data in Cache Existing data from the cache can be updated through `updateCacheValue()` method.It comes with the following two variants, ### Update cache value of a key This variant updates the value of the existing key, by passing the updated value as parameter to the `updateCacheValue()` method. The expiry time of the key is maintained as its previous value. #### Sample Code Snippet **Package Imports** ```java import com.zc.component.cache.ZCCache; import com.zc.component.cache.ZCSegment; ``` ```java //Get a Cache Instance ZCCache cacheobj=ZCCache.getInstance(); //Get an instance of a specific segment with a segment ID ZCSegment segment = cacheobj.getSegment(1510000000054091L); //replace segment id // Updates the value of the existing cache’s key ZCCache.getInstance().updateCacheValue("time_taken", "10"); ``` ### Update cache value with expiry time Similar to the above one, this variant updates the value of the key, where the expiry time of the key is also passed as the parameter to the method. The value of the expiry time is updated with the new value passed as a long int value in hours. #### Sample Code Snippet **Package Imports** ```java import com.zc.component.cache.ZCCache; import com.zc.component.cache.ZCSegment; ``` ```java //Get a Cache Instance ZCCache cacheobj=ZCCache.getInstance(); //Get an instance of a specific segment with a segment ID ZCSegment segment = cacheobj.getSegment(151xxxxxxxxxL); //Update the value of the existing cache’s key with its expiry time ZCCache.getInstance().updateCacheValue("time_taken", "48", 2L); ```