First Hand on JCS
Java Caching system (JCS) is open source java based caching system. JCS is useful for high read , low put application. The base of JCS is the Composite Cache, which is the pluggable controller for a cache region. There are fews terms relatated to JCS such as Element, Region, Auxiliaries etc
JCS is an object cache, exactly like putting object in hashtables. These objects are nothing but elements and each hashtable is Cache Region and customisable plugins to region are Auxiliaries.
You can read more about JCS at
This tutorial gives simple steps to get JCS working.
2. JCS needs two more jar files
1. common-logging.jar
You will get this jar from apache tomcat installtion
2. concurrent.jar
Once you download source code , compile it and make jar file named as concurrent.jar
3. Make sure that these three jars in classpath to use JCS
4. JCS is configured using cache.ccf property file. This property file defines all regions as well as auxiliaries. This configuraion files has to be in classpath, best place to keep it is right under classes folder. For example if you package struc is like "com.cache" then configuration file should present under classes folder with "com" folder.
By default this configuration file is named as "cache.ccf" , but you can give some other name provided that you should set configuration file name before instatiating cache.
Sample configuration is
# DEFAULT CACHE REGION
jcs.default=DC
jcs.default.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes
jcs.default.cacheattributes.MaxObjects=1000
cs.default.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache
jcs.default.cacheattributes.UseMemoryShrinker=false
jcs.default.cacheattributes.MaxMemoryIdleTimeSeconds=3600
jcs.default.cacheattributes.ShrinkerIntervalSeconds=60
jcs.default.elementattributes=org.apache.jcs.engine.ElementAttributes
jcs.default.elementattributes.IsEternal=false
jcs.default.elementattributes.MaxLifeSeconds=21600
jcs.default.elementattributes.IdleTime=1800
jcs.default.elementattributes.IsSpool=true
jcs.default.elementattributes.IsRemote=true
jcs.default.elementattributes.IsLateral=true
# PRE-DEFINED CACHE REGIONS
jcs.region.testCache1=DC
jcs.region.testCache1.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes
jcs.region.testCache1.cacheattributes.MaxObjects=1000
cs.region.testCache1.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache
jcs.region.testCache1.cacheattributes.UseMemoryShrinker=false
jcs.region.testCache1.cacheattributes.MaxMemoryIdleTimeSeconds=3600
jcs.region.testCache1.cacheattributes.ShrinkerIntervalSeconds=60
jcs.region.testCache1.cacheattributes.MaxSpoolPerRun=500
jcs.region.testCache1.elementattributes=org.apache.jcs.engine.ElementAttributes
jcs.region.testCache1.elementattributes.IsEternal=false
# AVAILABLE AUXILIARY CACHES
jcs.auxiliary.DC=org.apache.jcs.auxiliary.disk.indexed.IndexedDiskCacheFactory
jcs.auxiliary.DC.attributes=org.apache.jcs.auxiliary.disk.indexed.IndexedDiskCacheAttributes
jcs.auxiliary.DC.attributes.DiskPath=${user.dir}/jcs_swap
jcs.auxiliary.DC.attributes.MaxPurgatorySize=10000000
jcs.auxiliary.DC.attributes.MaxKeySize=1000000 jcs.auxiliary.DC.attributes.MaxRecycleBinSize=5000
jcs.auxiliary.DC.attributes.OptimizeAtRemoveCount=300000
jcs.auxiliary.DC.attributes.ShutdownSpoolTimeLimit=60
6. Instatiate Cache
import org.apache.jcs.JCS;
import org.apache.jcs.access.exception.CacheException;
JCS cache = JCS.getInstance("testCache1");
You can specify custom cache configuration name using
JCS.setConfigFileName("custome_cache.ccf");
JCS.getInstance("testCache1");
7. Start Using
cache.put("One","One");
System.out.println(cache.get("One");
reresZcamo Ana Brown https://wakelet.com/wake/sTNGbajk0n6C74xUKnuOs
ReplyDeleteabomuntran