我正在开发一个带有JCS 1.3缓存的web应用程序。
我需要在运行时从JVM属性编辑索引磁盘辅助缓存的DiskPath。
你知道怎么做吗?
我设法创建了AuxiliaryCache对象,但我不知道如何将它与cache.ccf中定义的所有区域连接起来。
下面是创建磁盘缓存的代码:IndexedDiskCacheAttributes indexedCacheAttr = new IndexedDiskCacheAttributes();
indexedCacheAttr.setMaxKeySize(10000);
indexedCacheAttr.setMaxRecycleBinSize(10000);
indexedCacheAttr.setMaxPurgatorySize(10000);
indexedCacheAttr.setOptimizeAtRemoveCount(5000);
String cacheDir = System.getProperty("xxxxx");
if (cacheDir == null || cacheDir.trim().length() == 0) {
log.error("error:JCSManager xxxx.");
} else {
indexedCacheAttr.setDiskPath(cacheDir);
}
IndexedDiskCacheManager indexedCacheManager =
IndexedDiskCacheManager.getInstance(indexedCacheAttr);
// instance du cache disque
AuxiliaryCache auxCache = indexedCacheManager.getCache(region);
获取一个区域,我使用以下命令:
JCS cache = JCS.getInstance(region);
有什么主意吗?
我们最终从web应用程序的类路径中提取了JCS配置文件(cache.ccf)。
我为这个文件添加了一个JVM属性。在访问JCS区域之前,我加载属性,然后使用CompositeCacheManager类来配置JCS。
String jcsConfFile = System.getProperty("XXXXXX");
if (jcsConfFile == null || jcsConfFile.trim().length() == 0) {
log.error("error:JCSManager .........");
} else {
Properties props = new Properties();
try {
// load a properties file
props.load(new FileInputStream(jcsConfFile));
} catch (IOException e) {
log.error("error:JCSManager ........", e);
}
CompositeCacheManager ccm = CompositeCacheManager.getUnconfiguredInstance();
ccm.configure(props);
}
//....
// later, ask for the region
JCS cache = JCS.getInstance(region);
解决方案来源