JCS edit Disk Auxiliary Cache DiskPath

这一生的挚爱 提交于 2019-12-10 14:00:25

问题


I am developping a web app with JCS 1.3 caching.

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 ?

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);

An idea please ?


回答1:


We finally extracted the JCS conf file (cache.ccf) from the classpath of the web app.

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);

source of the solution



来源:https://stackoverflow.com/questions/15297855/jcs-edit-disk-auxiliary-cache-diskpath

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!