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.

Ensure the following packages are imported:

    
copy
import com.zc.component.cache.ZCCache; import com.zc.component.cache.ZCSegment;
    
copy
//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.

Ensure the following packages are imported:

    
copy
import com.zc.component.cache.ZCCache; import com.zc.component.cache.ZCSegment;
    
copy
//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);

Last Updated 2023-09-03 01:06:41 +0530 +0530