public CacheConfigurationBuilder(final String name) { this.path = "ehcache.cache." + name; this.cache = new CacheConfiguration(); cache.setName(name); }
public GoCacheFactory(TransactionSynchronizationManager transactionSynchronizationManager, @Value("${cruise.cache.elements.limit}") int maxElementsInMemory, @Value("${cruise.cache.is.eternal}") boolean eternal) { this.transactionSynchronizationManager = transactionSynchronizationManager; cacheConfiguration = new CacheConfiguration("goCache", maxElementsInMemory) .persistence(new PersistenceConfiguration().strategy(PersistenceConfiguration.Strategy.NONE)) .eternal(eternal) .memoryStoreEvictionPolicy(MemoryStoreEvictionPolicy.LRU); }
private static CacheConfiguration cacheConfiguration(String cacheName) { return new CacheConfiguration(cacheName, 1024) .memoryStoreEvictionPolicy(MemoryStoreEvictionPolicy.LRU) .overflowToDisk(false) .diskPersistent(false); }
private static CacheConfiguration cacheConfiguration(String cacheName) { return new CacheConfiguration(cacheName, 1024) .memoryStoreEvictionPolicy(MemoryStoreEvictionPolicy.LRU) .overflowToDisk(false) .diskPersistent(false); }
@Before public void setup() { cacheManager = new CacheManager(new Configuration().name("EhCacheCacheTests") .defaultCache(new CacheConfiguration("default", 100))); nativeCache = new net.sf.ehcache.Cache(new CacheConfiguration(CACHE_NAME, 100)); cacheManager.addCache(nativeCache); cache = new EhCacheCache(nativeCache); }
private static CacheConfiguration cacheConfiguration() { return new CacheConfiguration(CACHE_NAME, 2048) .persistence(new PersistenceConfiguration().strategy(PersistenceConfiguration.Strategy.NONE)) .timeToIdleSeconds(120) .timeToLiveSeconds(0) .eternal(false) .memoryStoreEvictionPolicy(MemoryStoreEvictionPolicy.LRU); }
@Configuration @EnableCaching public class CachingConfig implements CachingConfigurer { @Bean(destroyMethod="shutdown") public net.sf.ehcache.CacheManager ehCacheManager() { CacheConfiguration cacheConfiguration = new CacheConfiguration(); cacheConfiguration.setName("myCacheName"); cacheConfiguration.setMemoryStoreEvictionPolicy("LRU"); cacheConfiguration.setMaxEntriesLocalHeap(1000); net.sf.ehcache.config.Configuration config = new net.sf.ehcache.config.Configuration(); config.addCache(cacheConfiguration); return net.sf.ehcache.CacheManager.newInstance(config); } @Bean @Override public CacheManager cacheManager() { return new EhCacheCacheManager(ehCacheManager()); } @Bean @Override public KeyGenerator keyGenerator() { return new SimpleKeyGenerator(); } }
private synchronized Cache getHeap() { if (heap == null) { if (CacheManager.getInstance().cacheExists("hydrated-cache")) { heap = CacheManager.getInstance().getCache("hydrated-cache"); } else { CacheConfiguration config = new CacheConfiguration("hydrated-cache", 0).eternal(true).overflowToDisk(false).maxElementsInMemory(100000); Cache cache = new Cache(config); CacheManager.create().addCache(cache); heap = cache; } } return heap; }
private synchronized Cache getHeap() { if (offHeap == null) { if (CacheManager.getInstance().cacheExists("hydrated-offheap-cache")) { offHeap = CacheManager.getInstance().getCache("hydrated-offheap-cache"); } else { CacheConfiguration config = new CacheConfiguration("hydrated-offheap-cache", 500).eternal(true).overflowToOffHeap(true).maxMemoryOffHeap("1400M"); Cache cache = new Cache(config); CacheManager.create().addCache(cache); offHeap = cache; } } return offHeap; }
@Before public void setup() { nativeCacheManager = new CacheManager(new Configuration().name("EhCacheCacheManagerTests") .defaultCache(new CacheConfiguration("default", 100))); addNativeCache(CACHE_NAME); cacheManager = new EhCacheCacheManager(nativeCacheManager); cacheManager.setTransactionAware(false); cacheManager.afterPropertiesSet(); transactionalCacheManager = new EhCacheCacheManager(nativeCacheManager); transactionalCacheManager.setTransactionAware(true); transactionalCacheManager.afterPropertiesSet(); }
new Cache(new CacheConfiguration("test", 0).//
/** * Configures a cache bean from a string of XML. */ public static CacheConfiguration parseCacheConfiguration(String xmlString) throws CacheException { CacheConfiguration cacheConfiguration = new CacheConfiguration(); try { InputSource source = new InputSource(new StringReader(xmlString)); final SAXParser parser = SAXParserFactory.newInstance().newSAXParser(); final BeanHandler handler = new BeanHandler(cacheConfiguration); parser.parse(source, handler); } catch (Exception e) { throw new CacheException("Error configuring from input stream. Initial cause was " + e.getMessage(), e); } return cacheConfiguration; }
@Bean public Cache cache() { CacheManager cacheManager = cacheManager(); Cache apiKeyCache = cacheManager.getCache(CACHE_NAME); if (apiKeyCache == null) { LOGGER.warn("EHCache cache for " + CACHE_NAME + " not found. Fallback to default EHCache configuration"); CacheConfiguration cacheConfiguration = new CacheConfiguration(CACHE_NAME, 1000); cacheManager.addCache(new Cache(cacheConfiguration)); } return cacheManager.getCache(CACHE_NAME); }
@Bean public Cache cache() { CacheManager cacheManager = cacheManager(); Cache apiKeyCache = cacheManager.getCache(API_KEY_CACHE_NAME); if (apiKeyCache == null) { LOGGER.warn("EHCache cache for apikey not found. Fallback to default EHCache configuration"); CacheConfiguration cacheConfiguration = new CacheConfiguration(API_KEY_CACHE_NAME, 1000); cacheManager.addCache(new Cache(cacheConfiguration)); } return cacheManager.getCache(API_KEY_CACHE_NAME); }
private static CacheConfiguration createCacheConfiguration(OpenmrsCacheConfiguration openmrsCacheConfiguration) { CacheConfiguration cacheConfiguration = new CacheConfiguration(); openmrsCacheConfiguration.getAllKeys() .forEach(key -> { try { BeanUtils.setProperty(cacheConfiguration, key, openmrsCacheConfiguration.getProperty(key)); } catch (IllegalAccessException | InvocationTargetException e) { throw new IllegalStateException(e); } }); return cacheConfiguration; }
boolean eternal, long timeToLiveSeconds, long timeToIdleSeconds) { this(new CacheConfiguration(name, maxElementsInMemory) .overflowToDisk(overflowToDisk) .eternal(eternal)
private void initSupportCache() { this.supportConfig = new CacheConfiguration(); supportConfig.name(underlyingCache.getName() + "_" + getClass().getName() + "_refreshAheadSupport"); supportConfig = supportConfig.persistence(new PersistenceConfiguration().strategy(Strategy.NONE));
boolean isTerracottaClustered, boolean terracottaCoherentReads) { this(new CacheConfiguration(name, maxElementsInMemory) .memoryStoreEvictionPolicy(memoryStoreEvictionPolicy) .overflowToDisk(overflowToDisk)
long diskExpiryThreadIntervalSeconds) { this(new CacheConfiguration(name, maxElementsInMemory) .overflowToDisk(overflowToDisk) .eternal(eternal) RegisteredEventListeners registeredEventListeners) { this(new CacheConfiguration(name, maxElementsInMemory) .memoryStoreEvictionPolicy(memoryStoreEvictionPolicy) .overflowToDisk(overflowToDisk) this(new CacheConfiguration(name, maxElementsInMemory) .memoryStoreEvictionPolicy(memoryStoreEvictionPolicy) .overflowToDisk(overflowToDisk) this(new CacheConfiguration(name, maxElementsInMemory) .memoryStoreEvictionPolicy(memoryStoreEvictionPolicy) .overflowToDisk(overflowToDisk) this(new CacheConfiguration(name, maxElementsInMemory) .memoryStoreEvictionPolicy(memoryStoreEvictionPolicy) .overflowToDisk(overflowToDisk) this(new CacheConfiguration(name, maxElementsInMemory) .memoryStoreEvictionPolicy(memoryStoreEvictionPolicy) .overflowToDisk(overflowToDisk)
public static CachePool createEnCachePool() { CacheConfiguration cacheConf = new CacheConfiguration(); cacheConf.setName("testcache"); cacheConf.maxBytesLocalHeap(400, MemoryUnit.MEGABYTES) .timeToIdleSeconds(3600); Cache cache = new Cache(cacheConf); CacheManager.create().addCache(cache); EnchachePool enCachePool = new EnchachePool(cacheConf.getName(), cache, 400 * 10000); return enCachePool; }