Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JCS edit Disk Auxiliary Cache DiskPath

Tags:

java

caching

jcs

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 ?

like image 475
Dino Avatar asked Nov 03 '22 03:11

Dino


1 Answers

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

like image 114
Dino Avatar answered Nov 15 '22 00:11

Dino