问题描述
我正在开发具有JCS 1.3缓存的Web应用程序.
I am developping a web app with JCS 1.3 caching.
我需要在运行时从JVM属性编辑索引磁盘辅助高速缓存的DiskPath.
I need to edit the DiskPath of the Indexed Disk Auxiliary Cache at runtime from a JVM property.
您知道这样做的方法吗?
Do you know a way to do this ?
我设法创建了AuxiliaryCache对象,但是我不知道如何将其与我在cache.ccf中定义的所有区域连接起来.
I managed to create the AuxiliaryCache object but I don't know how to connect it with all my regions defined in cache.ccf.
以下是创建磁盘缓存的代码:
Here is the code creating the disk cache :
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);
要获取区域,请使用以下内容:
To get a region I use the following :
JCS cache = JCS.getInstance(region);
请问一个主意?
推荐答案
我们终于从Web应用程序的类路径中提取了JCS conf文件(cache.ccf).
We finally extracted the JCS conf file (cache.ccf) from the classpath of the web app.
我为此文件添加了JVM属性.在访问JCS区域之前,我先加载属性,然后使用CompositeCacheManager类配置JCS.
I added a JVM property for this file. Before accessing to the JCS regions, I load the properties then use the CompositeCacheManager class to configure 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);
这篇关于JCS编辑磁盘辅助缓存DiskPath的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!