Memory and disk cache with JCS 1.3

trying to implement memory and disk cache with JCS v1.3, got information from docs and series of threads here on stackoverflow but still has no solution.
My test is simple:

  • load JCS;
  • save the item to the cache;
  • Terminate JCS.
    After that I want:
  • reload JCS:
  • get the same item from the cache.

I am getting null here. I can see both files region.data and region.key when I build, but for some reason I cannot get the item back, despite debugging and looking for the correct key in the auxiliary disk cache, there is no value in it and hence get returns nothing to me.

Can anyone help me?

Code:

private void performSimplerObjectPersistingInMemoryAndDisk(String configFile, String expected) throws Exception {

                    String key = "key", value = "value"; 
        JCS.setConfigFilename(configFile);
        JCS cache = JCS.getInstance("OUR_REGION");
        cache.put(key, value);
        Thread.sleep(5000);
        Assert.assertNotNull(cache.get(key));
        Assert.assertEquals(value, cache.get(key));
        System.out.println(cache.getStats());
        CompositeCacheManager.getInstance().shutDown();
        Thread.sleep(5000);
        JCS.setConfigFilename(configFile);
        cache = JCS.getInstance("OUR_REGION");
        Assert.assertEquals(expected, cache.get(key));
        System.out.println(cache.getStats());
    }

      

JCS config:

# DEFAULT CACHE REGION
jcs.default=DISK_REGION
jcs.default.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes
jcs.default.cacheattributes.MaxObjects=1000
jcs.default.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache
jcs.default.cacheattributes.DiskUsagePatternName=UPDATE
jcs.default.elementattributes=org.apache.jcs.engine.ElementAttributes
jcs.default.elementattributes.IsSpool=true

jcs.region.OUR_REGION=DISK_REGION
jcs.region.OUR_REGION.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes
jcs.region.OUR_REGION.cacheattributes.MaxObjects=0
jcs.region.OUR_REGION.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache
jcs.region.OUR_REGION.cacheattributes.UseMemoryShrinker=true
jcs.region.OUR_REGION.cacheattributes.MaxMemoryIdleTimeSeconds=3600
jcs.region.OUR_REGION.cacheattributes.ShrinkerIntervalSeconds=60
jcs.region.OUR_REGION.cacheattributes.MaxSpoolPerRun=500
jcs.region.OUR_REGION.elementattributes=org.apache.jcs.engine.ElementAttributes
jcs.region.OUR_REGION.elementattributes.IsEternal=false

jcs.auxiliary.DISK_REGION=org.apache.jcs.auxiliary.disk.indexed.IndexedDiskCacheFactory
jcs.auxiliary.DISK_REGION.attributes=org.apache.jcs.auxiliary.disk.indexed.IndexedDiskCacheAttributes
jcs.auxiliary.DISK_REGION.attributes.DiskPath=/tmp/jcs/cache
jcs.auxiliary.DISK_REGION.attributes.maxKeySize=100000

      

+3


source to share





All Articles