memory & disk cache with JCS 1.3

948 views Asked by At

having been trying to implement a memory & disk cache with JCS v1.3, got info from docs and a series of threads here in stackoverflow, but still not having any solution.
My test is simply:

  • load JCS;
  • save an element to the cache;
  • shutdown JCS gradefully.
    After this I want to :
  • reload JCS:
  • get that same element from the cache.

I'm getting a null here. I see both files, region.data and region.key, being created, but for some reason I can't get the element back, despite debugging and finding the correct key in the auxiliary disk cache, there's no value in it, and thus get doesn't delivers nothing back to me.

Can anyone provide me some help?

The code is:

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 is:

# 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
0

There are 0 answers