JCS Cache - Remove Functionality not removing specific Element
jcs Cache configs for our application are as below, I see that when we use fulshAll() method it removes the entire cache but when we use remove(key) it is not removing that object. Can someone please suggest.
public static void init( java.util.Properties properties ) {
java.util.Properties cacheProperties = new java.util.Properties();
java.util.regex.Pattern cachePattern =
java.util.regex.Pattern.compile("^jcs.*");
for (String key:properties.stringPropertyNames()) {
Matcher cacheMatcher = cachePattern.matcher(key);
if ( cacheMatcher.find() ) {
cacheProperties.setProperty(key,properties.getProperty(key));
}
}
CompositeCacheManager ccm =
CompositeCacheManager.getUnconfiguredInstance();
ccm.configure(cacheProperties);
miscCacheAdministrator = JCS.getInstance("miscCache");
metaDataCacheAdministrator = JCS.getInstance("metaDataCache");
resultCacheAdministrator = JCS.getInstance("resultCache");
}
And I am putting a element in cache and removing it for demo here.
public static void ExampleCache(String key){
resultCacheAdministrator.put(key, "Temp Cache");
resultCacheAdministrator.remove(key);
logger.debug(" Flushing a Particular Cache "+key);
}
When the PUT is called , I see the object is stored with 1kb, I immediately call the remove with the same key just for testing and I see the object is still there and not removed from cache, I was expecting 1kb to be 0, Please let me know what wrong am I doing here, Why the cache object is not removed from the file cache.
Properties File
# cache settings
jcs.region.resultCache=DC
jcs.region.resultCache.cacheattributes.MaxObjects=0
jcs.region.resultCache.elementattributes.IsEternal=false
jcs.region.resultCache.elementattributes.MaxLife=14400
jcs.region.resultCache.elementattributes.IsSpool=true
jcs.region.resultCache.cacheattributes=org.apache.commons.jcs.engine.
CompositeCacheAttributes
# Disk Cache Event Queue Pool
thread_pool.disk_cache_event_queue.useBoundary=false
thread_pool.disk_cache_event_queue.maximumPoolSize=3
thread_pool.disk_cache_event_queue.minimumPoolSize=1
thread_pool.disk_cache_event_queue.keepAliveTime=3500
thread_pool.disk_cache_event_queue.startUpSize=1

From the information provided, there is no fact that rises prove to the assumption of shrinking disk file.
For a short answer:
From the configuration presented, you might expect getting the expected behavior by setting
BTW, looking at the code you may recognize that the value of said property must be
> 0for enabling optimizing during runtime.For a longer explanation:
When talking about disk files we are talking about implementations of
AbstractDiskCacheclass. There currently are three sub-classes of this:BlockDiskCache,IndexedDiskCache,JDBCDiskCache.BlockDiskCachedoes not exhibit any mechanism for managing the size of the resulting file. The protectedfreeBlocksmethod is just documented to "Add these blocks to the emptyBlock list".JDBCDiskCacheis quite obviously delegating the task of managing storage size to the underlying database system.This leaves
IndexedDiskCache. As the default implementation, it likely is being used in your case.This class exhibits
optimizeFile()method that indicates the desired functionality. During optimize the data file is being compacted and the resulting file is reduced in size.Such optimizing is being triggered in case of one of two events:
on shutdown
Documentation on
OptimizeOnShutdownproperty states:By default the value is
true.after a number of removals
Documentation on
OptimizeAtRemoveCountproperty states:However, your properties do not show
OptimizeAtRemoveCountto be set. Thus, any freed items will be added to the free list for re-use but disk file size will not be reduced.From the distributed implementations of disk caches, only
IndexedDiskCacheprovides for reducing disk file size. You need to configure the optimize functionality properly for taking benefit of it. Anything else currently would require reverting to coding your own derived class.Another note:
Disk file optimization is not at all identical to Purgatory logic. The later relates to removing values from the cache itself. Such removal might then cause disk size reductions.