赞
踩
# PRE-DEFINED CACHE REGIONSjcs.region.proxyCache=DCjcs.region.proxyCache.cacheattributes=org.apache.jcs.engine.
CompositeCacheAttributesjcs.region.proxyCache.cacheattributes.MaxObjects=50jcs.region.proxyCache.cacheattributes.MemoryCacheName=org.apache.jcs.
engine.memory.lru.LRUMemoryCachejcs.region.proxyCache.cacheattributes.UseMemoryShrinker=truejcs.region.proxyCache.cacheattributes.MaxMemoryIdleTimeSeconds=3600jcs.region.proxyCache.cacheattributes.ShrinkerIntervalSeconds=60jcs.region.proxyCache.cacheattributes.MaxSpoolPerRun=500jcs.region.proxyCache.elementattributes=org.apache.jcs.engine.
ElementAttributesjcs.region.proxyCache.elementattributes.IsEternal=false# AVAILABLE AUXILIARY CACHES jcs.auxiliary.DC=org.apache.jcs.auxiliary.disk.indexed.
IndexedDiskCacheFactoryjcs.auxiliary.DC.attributes=org.apache.jcs.auxiliary.disk.
indexed.IndexedDiskCacheAttributesjcs.auxiliary.DC.attributes.DiskPath=./datajcs.auxiliary.DC.attributes.maxKeySize=100000
import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.IOException;import java.util.Properties;import org.apache.jcs.JCS;import org.apache.jcs.access.exception.CacheException;import org.apache.jcs.engine.control.CompositeCacheManager;import EDU.oswego.cs.dl.util.concurrent.Channel;public class WintimCache { private JCS jcs; private CompositeCacheManager ccm; public WintimCache() { try { ccm = CompositeCacheManager.getUnconfiguredInstance(); Properties props = new Properties(); props.load(new FileInputStream(new File("./conf/cache.ccf"))); ccm.configure(props); jcs = JCS.getInstance("proxyCache"); } catch (CacheException e) { ProxyLogger.getSysLogger().severe( "Error creating cache;Cause:" + e.getMessage()); }catch (FileNotFoundException e) { ProxyLogger.getSysLogger().severe(e.getMessage()); } catch (IOException e) { ProxyLogger.getSysLogger().severe( "Error reading file ./conf/cache.ccf ;Cause:" + e.getMessage()); } } public byte[] getResponse(String request) { return (byte[]) jcs.get(request); } public void addCacheItem(String request, byte[] response) { try { jcs.put(request, response); } catch (CacheException e) { ProxyLogger.getSysLogger().warning( "Error adding to cache;Cause:" + e.getMessage()); } }}