3

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.

enter image description here

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
Hero
  • 639
  • 4
  • 12
  • 33

1 Answers1

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

jcs.region.resultCache.cacheattributes.OptimizeAtRemoveCount=1

BTW, looking at the code you may recognize that the value of said property must be > 0 for enabling optimizing during runtime.

For a longer explanation:

When talking about disk files we are talking about implementations of AbstractDiskCache class. There currently are three sub-classes of this:
BlockDiskCache, IndexedDiskCache, JDBCDiskCache.

  • BlockDiskCache does not exhibit any mechanism for managing the size of the resulting file. The protected freeBlocks method is just documented to "Add these blocks to the emptyBlock list".

  • JDBCDiskCache is 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 OptimizeOnShutdown property states:

    By default the Indexed Disk Cache will optimize on shutdown if the free data size is greater than 0. If you want to prevent this behavior, you can set this parameter to false.

    By default the value is true.

  • after a number of removals
    Documentation on OptimizeAtRemoveCount property states:

    At how many removes should the cache try to defragment the data file. Since we recycle empty spots, defragmentation is usually not needed. To prevent the cache from defragmenting the data file, you can set this to -1. This is the default value.

However, your properties do not show OptimizeAtRemoveCount to 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 IndexedDiskCache provides 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.

rpy
  • 3,953
  • 2
  • 20
  • 31