JCS(Javc Caching System) – Persisting cache to disk

You can read in details about JCS here : JCS(Javc Caching System)

JCS primarily stores the cache in memory. But we can configure auxillary caches like disk, database, remote etc so that cache can be persisted their once it reaches the in-memory limit. But I had a requirement where I wanted all caches to be persisted to disk and not in memory. So here is the cache.ccf file with such configuration

##############################################################
##### Default Region Configuration
jcs.default=DC
jcs.default.cacheattributes=org.apache.commons.jcs.engine.CompositeCacheAttributes
jcs.default.cacheattributes.MaxObjects=0
jcs.default.cacheattributes.MemoryCacheName=org.apache.commons.jcs.engine.memory.lru.LRUMemoryCache
jcs.default.cacheattributes.DiskUsagePatternName=UPDATE

##############################################################
##### CACHE REGIONS
jcs.region.myRegion1=DC
jcs.region.myRegion1.cacheattributes=org.apache.commons.jcs.engine.CompositeCacheAttributes
jcs.region.myRegion1.cacheattributes.MemoryCacheName=org.apache.commons.jcs.engine.memory.lru.LRUMemoryCache
jcs.region.myRegion1.cacheattributes.DiskUsagePatternName=UPDATE
jcs.region.myRegion1.elementattributes.IsEternal=true
jcs.region.myRegion1.cacheattributes.MaxObjects=0

##############################################################
##### AUXILIARY CACHES
# Indexed Disk Cache
jcs.auxiliary.DC=org.apache.commons.jcs.auxiliary.disk.indexed.IndexedDiskCacheFactory
jcs.auxiliary.DC.attributes=org.apache.commons.jcs.auxiliary.disk.indexed.IndexedDiskCacheAttributes
jcs.auxiliary.DC.attributes.diskPath=c:/downloads/cache
jcs.auxiliary.DC.attributes.MaxPurgatorySize=10000
jcs.auxiliary.DC.attributes.MaxKeySize=10000
jcs.auxiliary.DC.attributes.OptimizeAtRemoveCount=300000
jcs.auxiliary.DC.attributes.OptimizeOnShutdown=true
jcs.auxiliary.DC.attributes.DiskLimitType=COUNT

Key attribute to note here is jcs.default.cacheattributes.MaxObjects which has been set to 0. This means any entry to cache will be persisted to the disk. Disk location is specified by jcs.auxiliary.DC.attributes.diskPath attribute

 

Mar Java Mit Java 🙂

Uday Ogra

Connect with me at http://facebook.com/tendulkarogra and lets have some healthy discussion :)

You may also like...

Leave a Reply

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