3

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
  • Have you arrived at the answer? – Cybermonk Mar 08 '16 at 11:39
  • no unfortunately, what I require is simply not implemented yet, got this info from the dev team: On 14.11.14 19:14, joao tiago a. m. viegas wrote: > thank you Thomas, but is there anyway to persist and reload the cache with > 1.3? Unfortunately not. Sorry. JCS 1.3 is full of static classes which are not re-initialized properly. I tried to address most of these problems in 2.0, but still a few remain. – joão tiago viegas Mar 08 '16 at 13:25
  • Hey, this works in 2.1...it will pre-load from Disk – Jeryl Cook Aug 11 '17 at 18:56
  • Great, will have a go at it soon. Thank you – joão tiago viegas Aug 13 '17 at 07:29

0 Answers0