Code snippet used to allocate cache memory:
private static Cache cache = CacheManager.getInstance().getCache(CACHE_NAME);
public static HashMap<String, XXX> getxxCodes(int version) {
HashMap<String, XXX> xxCodes = new HashMap<String, XXX>();
try{
Object[] cacheResult = cache.get(Constants.I_XX_CODES_FOR_XXX);
if (Boolean.FALSE.equals(cacheResult[1])) {
cache.put(Constants.I_XX_CODES_FOR_XXX, id.loadXXHashMap(version));
cacheResult = cache.get(Constants.I_XX_CODES_FOR_XXX);
}
if(cacheResult[0]!=null){
xxCodes = (HashMap<String, XXX>)cacheResult[0];
}
}catch(Exception e){
logger.error("Exception occured while loading Data from I10_DRG_XX",e);
}
return xxCodes;
}
Now at some point of time I need to load some other “version” into the cache memory. Here version can be 1, 2, 3 etc. So the cache first holds version 1 data (Hash map). Now when I am passing 2 which is unavailable in cache it needs to load specific data again into cache, but before that it is better to clear version 1 data. Do we have commands like flush to clear specific data?
I hope I am clear with my question. Thanks for helping.
I have used the following code and its working correctly,
This will delete the Instance of cache from memory.
Thanks for all your help.