Retrieve data from the 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:

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

Copiedimport com.zc.component.cache.ZCCache;
import com.zc.component.cache.ZCCacheObject;
import com.zc.component.cache.ZCSegment;
Copied//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 Cache object using key
ZCCacheObject cacheValue= segment.getCacheObject("Name");