简体   繁体   English

JCS编辑磁盘辅助缓存DiskPath

[英]JCS edit Disk Auxiliary Cache DiskPath

I am developping a web app with JCS 1.3 caching. 我正在使用JCS 1.3缓存开发Web应用程序。

I need to edit the DiskPath of the Indexed Disk Auxiliary Cache at runtime from a JVM property. 我需要在运行时从JVM属性编辑索引磁盘辅助缓存的DiskPath。

Do you know a way to do this ? 你知道这样做的方法吗?

I managed to create the AuxiliaryCache object but I don't know how to connect it with all my regions defined in cache.ccf. 我设法创建了AuxiliaryCache对象,但我不知道如何将它与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);

An idea please ? 请问一个想法?

We finally extracted the JCS conf file (cache.ccf) from the classpath of the web app. 我们最终从Web应用程序的类路径中提取了JCS conf文件(cache.ccf)。

I added a JVM property for this file. 我为这个文件添加了一个JVM属性。 Before accessing to the JCS regions, I load the properties then use the CompositeCacheManager class to configure JCS. 在访问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);

source of the solution 解决方案的来源

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM