Apache Commons logo

Commons JCS™

Cache Region Configuration

The following properties apply to any cache region. They can be specified as default values and specified on a region by region basis. There are three types of settings: auxiliary, cache, and element. The cache settings define the memory management for the region. The element settings define default element behavior within the region.

Region (Auxiliary) Properties

Property Description Required Default Value
You can specify the list of auxiliaries that regions can use. This has no attribute name. The list can be empty, otherwise it should be comma delimited. Y n/a

Region (Cache) Properties

Property Description Required Default Value
MaxObjects The maximum number of items allowed in memory. Eviction of elements in excess of this number is determined by the memory cache. By default JCS uses the LRU memory cache. Y n/a
MemoryCacheName This property allows you to specify what memory manager you would like to use. You can create your own memory manager by implementing the org.apache.commons.jcs.engine.memory.MemoryCache interface. Alternatively, you can extend the org.apache.commons.jcs.engine.memory.AbstractMemoryCache class. Several different memory caches are available: two LRU implementations, an LFU, and an adaptive replacement algorithm. N org.apache.commons.jcs.engine.memory.lru.LRUMemoryCache
UseMemoryShrinker By default, the memory shrinker is shared by all regions that use the LRU memory cache. The memory shrinker iterates through the items in memory, looking for items that have expired or that have exceeded their max memory idle time. N false
MaxMemoryIdleTimeSeconds This is only used if you are using the memory shrinker. If this value is set above -1, then if an item has not been accessed in this number of seconds, it will be spooled to disk if the disk is available. You can register an event handler on this event. N 7200
ShrinkerIntervalSeconds This specifies how often the shrinker should run, if it has been activated. If you set UseMemoryShrinker to false, then this setting has no effect. N 60
DiskUsagePatternName SWAP is the default. Under the swap pattern, data is only put to disk when the max memory size is reached. Since items puled from disk are put into memory, if the memory cache is full and you get an item off disk, the lest recently used item will be spooled to disk. If you have a low memory hit ration, you end up thrashing. The UPDATE usage pattern allows items to go to disk on an update. It disables the swap. This allows you to persist all items to disk. If you are using the JDBC disk cache for instance, you can put all the items on disk while using the memory cache for performance, and not worry about losing data from a system crash or improper shutdown. Also, since all items are on disk, there is no need to swap to disk. This prevents the possibility of thrashing. N SWAP

Region (Element) Properties

Property Description Required Default Value
IsEternal If an element is specified as eternal, then it will never be subject to removal for exceeding its max life. N true
MaxLifeSeconds If you specify that elements within a region are not eternal, then you can set the max life seconds. If this is exceeded the elements will be removed passively when a client tries to retrieve them. If you are using a memory shrinker, then the items can be removed actively. N -1
IsSpool By default, can elements in this region be sent to a disk cache if one is available. N true
IsLateral By default, can elements in this region be sent to a lateral cache if one is available. N true
IsRemote By default, can elements in this region be sent to a remote cache if one is available. N true

Example Configuration

					
jcs.default=
jcs.default.cacheattributes=org.apache.commons.jcs.engine.CompositeCacheAttributes
jcs.default.cacheattributes.MaxObjects=200001
jcs.default.cacheattributes.MemoryCacheName=org.apache.commons.jcs.engine.memory.lru.LRUMemoryCache
jcs.default.cacheattributes.UseMemoryShrinker=true
jcs.default.cacheattributes.MaxMemoryIdleTimeSeconds=3600
jcs.default.cacheattributes.ShrinkerIntervalSeconds=60
jcs.default.elementattributes=org.apache.commons.jcs.engine.ElementAttributes
jcs.default.elementattributes.IsEternal=false
jcs.default.elementattributes.MaxLifeSeconds=700
jcs.default.elementattributes.IsSpool=true
jcs.default.elementattributes.IsRemote=true
jcs.default.elementattributes.IsLateral=true

# optional region "testCache1" specific configuration settings
jcs.region.testCache1=
jcs.region.testCache1.cacheattributes=org.apache.commons.jcs.engine.CompositeCacheAttributes
jcs.region.testCache1.cacheattributes.MaxObjects=123456
jcs.region.testCache1.cacheattributes.MemoryCacheName=org.apache.commons.jcs.engine.memory.lru.LRUMemoryCache
jcs.region.testCache1.cacheattributes.UseMemoryShrinker=true
jcs.region.testCache1.cacheattributes.ShrinkerIntervalSeconds=30
jcs.region.testCache1.cacheattributes.MaxMemoryIdleTimeSeconds=300
jcs.region.testCache1.cacheattributes.MaxSpoolPerRun=100
jcs.region.testCache1.elementattributes=org.apache.commons.jcs.engine.ElementAttributes
jcs.region.testCache1.elementattributes.IsEternal=false
jcs.region.testCache1.elementattributes.MaxLifeSeconds=60000
jcs.region.testCache1.elementattributes.IsSpool=true
jcs.region.testCache1.elementattributes.IsLateral=true
jcs.region.testCache1.elementattributes.IsRemote=true