JCS is an implementation of cache in Java. It supports caching data to the memory or hard disk and setting the effective duration of the cache object. The following JAR packages are required for use:
Commons-collections-2.1.1.jar
Commons-lang.2.3.jar
Commons-logging-1.0.4.jar
Concurrent-1.3.2.jar
Jcs-1.3.jar
Slf4j-api.jar
Define the storage object class that implements the serializable interface:
Public class userinfo implements serializable {<br/> private string username; <br/> private string domain; </P> <p> Public userinfo (string name) {<br/> This. username = Name; <br/>}</P> <p> Public userinfo (string name, string domain) {<br/> This. username = Name; <br/> This. domain = domain; <br/>}< br/>}
Define storage class:
Public class usermanager {<br/> private JCs jcscache; <br/> private final string name_space = "userinfo "; </P> <p> Private Static class usermanagercontainer {<br/> Private Static usermanager instance = new usermanager (); <br/>}</P> <p> Public static usermanager getinstance () {<br/> return usermanagercontainer. instance <br/>}</P> <p> private usermanager () {<br/> try {</P> <p> jcscache = JCs. getinstance (name_space); </P> <p >}< br/> catch (cacheexception E) {<br/>}</P> <p> Public userinfo get (string key) {<br/> return (userinfo) jcscache. get (key); <br/>}</P> <p> pubilc void put (string key, userinfo info, Boolean isoverride) {<br/> try {<br/> If (isoverride) {<br/> jcscache. put (Key, Info); <br/>}< br/> else {<br/> jcscache. putsafe (Key, Info); <br/>}< br/> catch (cacheexception E) {</P> <p >}< br/>}
Define the configuration file: cache. CCF
JCs. default = Dc <br/> JCs. defaultcacheattributes = org. engine. compositecacheattributes <br/> JCs. defaultcacheattributes. maxobjects = 500000 <br/> JCs. defaultcacheattributes. memorycachename = org. apache. JCs. engine. memory. LRU. lrumemorycache <br/> JCs. defaultcacheattributes. usememoryshrinker = true <br/> JCs. defaultcacheattributes. maxmemoryidletimeseconds = 1200 <br/> JCs. defaultcacheattributes. shrinkerintervalseconds = 30 <br/> JCs. defaultcacheattributes. maxspoolperexecute = 500 <br/> JCs. default. elementattributes = org. apache. JCs. engine. elementattributes <br/> JCs. default. elementattributes. iseternal = false <br/> JCs. auxiliary. dc = org. apache. JCs. auxiliary. disk. indexed. indexeddiskcachefactory <br/> JCs. auxiliary. DC. attributes = org. apache. JCs. auxiliary. disk. indexed. indexeddiskcacheattribute <br/> JCs. auxiliary. DC. attributes. diskpatch = D:/memory