/** * http://www.ehcache.org/documentation/2.8/code-samples.html#creating-caches-programmatically */ EhCacheWrapper(String cacheName) { AppConfiguration.Cache config = AppConfiguration.CONFIG.getCache(); // Create a Cache specifying its configuration cache = new Cache( new CacheConfiguration(cacheName, config.getMaxSize()) .timeToLiveSeconds(TimeUnit.MINUTES.toSeconds(config.getLifeTime())) .eternal(false) .persistence(new PersistenceConfiguration().strategy(Strategy.NONE)) .memoryStoreEvictionPolicy(MemoryStoreEvictionPolicy.FIFO) ); // The cache is not usable until it has been added manager.addCache(cache); }
public void setCacheValue(String cacheName, String keyName, Collection<Attribute> attrs, int tti, int ttl) { CacheManager manager = Context.getInstance().getCacheManager(); Cache cache = manager.getCache(cacheName); if (cache == null) { cache = new Cache( new CacheConfiguration(cacheName, 1000) .memoryStoreEvictionPolicy(MemoryStoreEvictionPolicy.LRU) .eternal(false) .timeToLiveSeconds(60) .timeToIdleSeconds(60) .diskExpiryThreadIntervalSeconds(120) .persistence(new PersistenceConfiguration().strategy(Strategy.LOCALTEMPSWAP))); manager.addCache(cache); } cache.put(new net.sf.ehcache.Element(keyName, attrs, false, tti, ttl)); }
private Cache getOrCreateCache() { // Create a singleton CacheManager using defaults CacheManager manager = CacheManager.create(); // Create a Cache specifying its configuration Cache c = manager.getCache(CACHE_name); if (c == null) { c = new Cache(new CacheConfiguration(CACHE_name, CACHE_maxEntriesLocalHeap) .memoryStoreEvictionPolicy(MemoryStoreEvictionPolicy.LFU) .eternal(true) .persistence( new PersistenceConfiguration() .strategy(Strategy.LOCALTEMPSWAP))); manager.addCache(c); } return c; }
public RealCache() { super(); CacheManager manager = null; synchronized (RealCache.class) { manager = CacheManager.getInstance(); if (!manager.cacheExists("AFPDataGrabberCache")) { Cache cache = new Cache(new CacheConfiguration("AFPDataGrabberCache", 50000).memoryStoreEvictionPolicy(MemoryStoreEvictionPolicy.LFU) .eternal(true).timeToLiveSeconds(0).timeToIdleSeconds(0).persistence(new PersistenceConfiguration().strategy(Strategy.NONE))); manager.addCache(cache); } } ehcache = manager.getCache("AFPDataGrabberCache"); }
public DefaultCacheManagerProvider() { net.sf.ehcache.config.Configuration config = new net.sf.ehcache.config.Configuration(); config.setUpdateCheck(false); CacheConfiguration tokenCacheConfiguration = new CacheConfiguration(). maxEntriesLocalHeap(DEFAULT_MAX_CACHE_ENTRIES). name("tokenCache"). persistence(new PersistenceConfiguration().strategy(Strategy.NONE)); tokenCacheConfiguration.validateConfiguration(); config.addCache(tokenCacheConfiguration ); cacheManager = CacheManager.create(config); }
@Nullable public Strategy getPersistenceStrategy() { return this.persistenceStrategy; }
public void setPersistenceStrategy(@Nullable Strategy persistenceStrategy) { this.persistenceStrategy = persistenceStrategy; }
public Strategy getPersistenceStrategy() { return this.persistenceStrategy; }
public void setPersistenceStrategy(Strategy persistenceStrategy) { this.persistenceStrategy = persistenceStrategy; }