3

一直在尝试使用 JCS v1.3 实现内存和磁盘缓存,从文档和 stackoverflow 中的一系列线程获取信息,但仍然没有任何解决方案。
我的测试很简单:

  • 加载 JCS;
  • 将元素保存到缓存中;
  • 逐步关闭 JCS。
    在此之后我想:
  • 重新加载 JCS:
  • 从缓存中获取相同的元素。

我在这里得到一个空值。我看到两个文件 region.data 和 region.key 都在创建中,但由于某种原因我无法取回元素,尽管在辅助磁盘缓存中调试并找到了正确的键,但其中没有任何价值,因此get 没有返回给我任何东西。

谁能给我一些帮助?

代码是:

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 配置为:

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

0 回答 0