2013-03-08 17 views
5

Sto sviluppando un'applicazione web con cache JCS 1.3.JCS edit Disk Auxiliary Cache DiskPath

Ho bisogno di modificare il DiskPath della cache ausiliaria del disco indicizzato in fase di runtime da una proprietà JVM.

Conosci un modo per farlo?

Sono riuscito a creare l'oggetto AuxiliaryCache ma non so come collegarlo con tutte le mie regioni definite in cache.ccf.

ecco il codice Creazione della cache del disco:

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

Per ottenere una regione Io uso il seguente:

JCS cache = JCS.getInstance(region); 

Un'idea per favore?

risposta

2

Abbiamo infine estratto il file conf JCS (cache.ccf) dal classpath dell'app Web.

Ho aggiunto una proprietà JVM per questo file. Prima di accedere alle regioni JCS, carico le proprietà quindi utilizzo la classe CompositeCacheManager per configurare 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