Retrieve Data from Cache

Retrieve the value by key name

Every cache segment contains key-value pairs. Both keys and values are String type. The value of a key is retrieved through the getCacheValue() method.

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 segment ID ZCSegment segment = cacheobj.getSegment(1510000000054091L); //Get The value of the cache object using key String cacheValue= segment.getCacheValue("Val");

Retrieve the cache object by key name

Another variant for retrieving a cache object is to return the corresponding value of a key as a cache object.

Note: The cache object contains all of its attributes such as key, value, and expiry time.

Ensure the following packages are imported:

    
copy
import com.zc.component.cache.ZCCache; import com.zc.component.cache.ZCCacheObject; import com.zc.component.cache.ZCSegment;
    
copy
//Get a Cache Instance ZCCache cacheobj=ZCCache.getInstance(); //Get an instance of a specific segment with segment ID ZCSegment segment = cacheobj.getSegment(1510000000054091L); //replace segment id //Get The Cache object using key ZCCacheObject cacheValue = segment.getCacheObject("Name"); // replace cache key

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