public void afterPropertiesSet() throws IOException, CacheException { log.info("Initializing EHCache CacheManager"); Configuration config = null; if (this.configLocation != null) { config = ConfigurationFactory .parseConfiguration(this.configLocation.getInputStream()); if (this.diskStoreLocation != null) { DiskStoreConfiguration dc = new DiskStoreConfiguration(); dc.setPath(this.diskStoreLocation.getFile().getAbsolutePath()); try { config.addDiskStore(dc); } catch (ObjectExistsException e) { log.warn("if you want to config distStore in spring," + " please remove diskStore in config file!", e); } } } if (config != null) { this.cacheManager = new CacheManager(config); } else { this.cacheManager = new CacheManager(); } if (this.cacheManagerName != null) { this.cacheManager.setName(this.cacheManagerName); } }
public void set(String tableName, String key, Object value) { try { cacheManager.addCacheIfAbsent(new Cache(tableName, conf.max_len, conf.overflowToDisk, conf.eternal, conf.expired_seconds, conf.expired_seconds)); Cache lru = cacheManager.getCache(tableName); lru.put(new Element(key, value)); } catch (ObjectExistsException ex) { } }
private Cache getApplicationCache() { Cache applicationCache = null; if(manager!=null && !manager.cacheExists(BusinessCacheManager.BUSINESS_TIER_CACHE)) { /** * Here are the parameters that we are using for creating the business * tier Application Cache * CacheName = REMBRANDT_CACHE; * Max Elements in Memory = 100; * Overflow to disk = false; * Make the cache eternal = true; * Elements time to live in seconds = 0 (Special setting which means never check); * Elements time to idle in seconds = 0 (Special setting which means never check); * */ applicationCache = new Cache(BusinessCacheManager.BUSINESS_TIER_CACHE, 100, false, true, 0, 0); logger.debug("New ApplicationCache created"); try { manager.addCache(applicationCache); }catch(ObjectExistsException oee) { logger.error("ApplicationCache creation failed."); logger.error(oee); }catch(CacheException ce) { logger.error("ApplicationCache creation failed."); logger.error(ce); } }else if(manager!=null){ applicationCache = manager.getCache(BusinessCacheManager.BUSINESS_TIER_CACHE); } return applicationCache; }
/** * */ public Cache getSessionCache(String sessionId) { Cache sessionCache = null; if( manager!=null && !manager.cacheExists(sessionId) ) { /** * Here are the parameters that we are using for creating the business * tier session caches * CacheName = the sessionId; * Max Elements in Memory = 1000; * Overflow to disk = false; * make the cache eternal = true; * elements time to live in seconds = 0 (Special setting which means never check); * elements time to idle in seconds = 0 (Special setting which means never check); * */ sessionCache = new Cache(sessionId, 1000, true, true, 0, 0); logger.debug("New SessionCache created: "+sessionId); Element counter = new Element(CacheConstants.REPORT_COUNTER, new SessionTempReportCounter()); try { manager.addCache(sessionCache); fireCacheAddEvent(sessionId); sessionCache.put(counter); }catch(ObjectExistsException oee) { logger.error("Attempted to create the same session cache twice."); logger.error(oee); }catch(CacheException ce) { logger.error("Attempt to create session cache failed."); logger.error(ce); } }else if(manager!=null){ sessionCache = manager.getCache(sessionId); } return sessionCache; }
/** * This method is the workhorse of the PresentationCacheManager, almost * every other mehtod makes use of this method to retrieve and create all * session caches for the cache manager. * * @param sessionId * @param createTempCounter * @return */ protected Cache getSessionCache(String sessionId) { Cache sessionCache = null; /* * Process the sessionId to make sure that we have a unique sessionName for * the presentation tier cache */ String uniqueSession = processSessionId(sessionId); if( manager!=null && !manager.cacheExists(uniqueSession) ) { /** * Here are the parameters that we are using for creating the presentation * tier session caches. These caches are only stored in Memory and * never persisted out to disk * * CacheName = the sessionId; * Max Elements in Memory = 1000; * Overflow to disk = false; * Make the cache eternal = true; * Elements time to live in seconds = 12000 (200 minutes, this not eternal in case the data changes); * Elements time to idle in seconds = 0 (Special setting which means never check); */ sessionCache = new Cache(uniqueSession, 10000, true, true, 0, 0); logger.debug("New Presentation SessionCache created: "+sessionId); try { manager.addCache(sessionCache); Element counter = new Element(CacheConstants.REPORT_COUNTER, new SessionTempReportCounter()); sessionCache.put(counter); }catch(ObjectExistsException oee) { logger.error("Attempted to create the same session cache twice."); logger.error(oee); }catch(CacheException ce) { logger.error("Attempt to create session cache failed."); logger.error(ce); } }else if(manager!=null){ logger.debug("Returning an existing session cache"); sessionCache = manager.getCache(uniqueSession); } return sessionCache; }
/** * Returns the Cache that is intended to be used to store application scoped * variables * @return */ private Cache getApplicationCache() { Cache applicationCache = null; if(manager!=null && !manager.cacheExists(PresentationCacheManager.PRESENTATION_CACHE)) { /** * Here are the parameters that we are using for creating the presentation * tier Application Cache * CacheName = PRESENTATION_CACHE; * Max Elements in Memory = 100; * Overflow to disk = false; * Make the cache eternal = true; * Elements time to live in seconds = 12000 (200 minutes, this not eternal in case the data changes); * Elements time to idle in seconds = 0 (Special setting which means never check); */ presentationCache = new Cache(PresentationCacheManager.PRESENTATION_CACHE, 100, false, true, 0, 0); logger.debug("New ApplicationCache created"); try { manager.addCache(presentationCache); }catch(ObjectExistsException oee) { logger.error("ApplicationCache creation failed."); logger.error(oee); }catch(CacheException ce) { logger.error("ApplicationCache creation failed."); logger.error(ce); } }else if(manager!=null){ presentationCache = manager.getCache(PresentationCacheManager.PRESENTATION_CACHE); } return presentationCache; }
/** * Returns the Cache that is intended to be used to store application scoped * variables * @return */ private Cache getApplicationCache() { Cache applicationCache = null; if(manager!=null && !manager.cacheExists(RembrandtPresentationCacheManager.PRESENTATION_CACHE)) { /** * Here are the parameters that we are using for creating the presentation * tier Application Cache * CacheName = PRESENTATION_CACHE; * Max Elements in Memory = 100; * Overflow to disk = false; * Make the cache eternal = true; * Elements time to live in seconds = 12000 (200 minutes, this not eternal in case the data changes); * Elements time to idle in seconds = 0 (Special setting which means never check); */ presentationCache = new Cache(RembrandtPresentationCacheManager.PRESENTATION_CACHE, 100, false, true, 0, 0); logger.debug("New ApplicationCache created"); try { manager.addCache(presentationCache); }catch(ObjectExistsException oee) { logger.error("ApplicationCache creation failed."); logger.error(oee); }catch(CacheException ce) { logger.error("ApplicationCache creation failed."); logger.error(ce); } }else if(manager!=null){ presentationCache = manager.getCache(RembrandtPresentationCacheManager.PRESENTATION_CACHE); } return presentationCache; }