How to add Auxiliary cache programitically in JCS - Mar Java Mit Java

How to add Auxiliary cache programitically in JCS

In JCS we can enable cache overflow/persistence to disk by using indexed disk cache. We can easily configure this in cache.ccf file like this :


What if you want to set this auxiliary cache from Java program or perhaps update the diskstore to some new value. Though there is no proper documentation, but I was able to figure out how to do that.


Here buy finast amazon cache is CompositeCache object, click here diskStore is the new diskpath for indexed cache and map contains other parameters which we could have passed in ccf file also

 private void setAuxiliaryCache(CompositeCache<Object, Object> cache, String diskStrore, Map<String, String> map)
        AuxiliaryCache<Object, Object>[] auxs = cache.getAuxCaches();
        IndexedDiskCacheAttributes idca = new IndexedDiskCacheAttributes();
        if(null != map && null != map.get(PROP_MAXELEMENTSONDISK)){
        if(null != map && null != map.get(PROP_MAXKEYSIZE)){
        AuxiliaryCache<Object, Object> aux = new IndexedDiskCache<Object, Object>(idca);
        List<AuxiliaryCache<Object, Object>> auxList = Arrays.asList(aux);
        for (AuxiliaryCache<Object, Object> auxCache : auxs)
            if (!(auxCache instanceof IndexedDiskCache))
                 * ((IndexedDiskCacheAttributes) ((IndexedDiskCache) auxCache).getAuxiliaryCacheAttributes())
                 * .setDiskPath(diskStrore);
        cache.setAuxCaches((AuxiliaryCache<Object, Object>[]) auxList.toArray());

Uday Ogra

Connect with me at and lets have some healthy discussion :)

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *