package com.mooveit.sgst.stock2; import org.jboss.seam.ScopeType; import org.jboss.seam.annotations.Create; import org.jboss.seam.annotations.Destroy; import org.jboss.seam.annotations.Name; import org.jboss.seam.annotations.Scope; import com.whirlycott.cache.Cache; import com.whirlycott.cache.CacheConfiguration; import com.whirlycott.cache.CacheException; import com.whirlycott.cache.CacheManager; @Name("stockCache") @Scope(ScopeType.APPLICATION) public class StockCache { //Use the cache manager to create the default cache private Cache c; @Create public void init(){ try { CacheConfiguration cc = new CacheConfiguration(); cc.setName("KBCache"); cc.setBackend("com.whirlycott.cache.impl.ConcurrentHashMapImpl"); cc.setTunerSleepTime(60); cc.setPolicy("com.whirlycott.cache.policy.LFUMaintenancePolicy"); cc.setMaxSize(10000); c = CacheManager.getInstance().createCache(cc); } catch (CacheException e) { // TODO Auto-generated catch block e.printStackTrace(); } } @Destroy public void destroy(){ //Shut down the cache manager try { CacheManager.getInstance().shutdown(); } catch (CacheException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public void remove(String key){ //Put an object into the cache c.remove(key); } public void put(String key, Object object){ //Put an object into the cache c.store(key, object); } public Object get(String key){ //Get the object back out of the cache return c.retrieve(key); } }