@Override public void afterPropertiesSet() throws Exception { if (this.serviceTicketsCache == null || this.ticketGrantingTicketsCache == null) { throw new BeanInstantiationException(this.getClass(), "Both serviceTicketsCache and ticketGrantingTicketsCache are required properties."); } if (logger.isDebugEnabled()) { CacheConfiguration config = this.serviceTicketsCache.getCacheConfiguration(); logger.debug("serviceTicketsCache.maxElementsInMemory={}", config.getMaxEntriesLocalHeap()); logger.debug("serviceTicketsCache.maxElementsOnDisk={}", config.getMaxElementsOnDisk()); logger.debug("serviceTicketsCache.isOverflowToDisk={}", config.isOverflowToDisk()); logger.debug("serviceTicketsCache.timeToLive={}", config.getTimeToLiveSeconds()); logger.debug("serviceTicketsCache.timeToIdle={}", config.getTimeToIdleSeconds()); logger.debug("serviceTicketsCache.cacheManager={}", this.serviceTicketsCache.getCacheManager().getName()); config = this.ticketGrantingTicketsCache.getCacheConfiguration(); logger.debug("ticketGrantingTicketsCache.maxElementsInMemory={}", config.getMaxEntriesLocalHeap()); logger.debug("ticketGrantingTicketsCache.maxElementsOnDisk={}", config.getMaxElementsOnDisk()); logger.debug("ticketGrantingTicketsCache.isOverflowToDisk={}", config.isOverflowToDisk()); logger.debug("ticketGrantingTicketsCache.timeToLive={}", config.getTimeToLiveSeconds()); logger.debug("ticketGrantingTicketsCache.timeToIdle={}", config.getTimeToIdleSeconds()); logger.debug("ticketGrantingTicketsCache.cacheManager={}", this.ticketGrantingTicketsCache.getCacheManager() .getName()); } }
/** * Instantiates a new EhCache ticket registry. * * @param ticketCache the ticket cache * @param cipher the cipher */ public EhCacheTicketRegistry(final Cache ticketCache, final CipherExecutor cipher) { this.ehcacheTicketsCache = ticketCache; setCipherExecutor(cipher); LOGGER.info("Setting up Ehcache Ticket Registry..."); Assert.notNull(this.ehcacheTicketsCache, "Ehcache Tickets cache cannot nbe null"); if (LOGGER.isDebugEnabled()) { final CacheConfiguration config = this.ehcacheTicketsCache.getCacheConfiguration(); LOGGER.debug("TicketCache.maxEntriesLocalHeap=[{}]", config.getMaxEntriesLocalHeap()); LOGGER.debug("TicketCache.maxEntriesLocalDisk=[{}]", config.getMaxEntriesLocalDisk()); LOGGER.debug("TicketCache.maxEntriesInCache=[{}]", config.getMaxEntriesInCache()); LOGGER.debug("TicketCache.persistenceConfiguration=[{}]", config.getPersistenceConfiguration().getStrategy()); LOGGER.debug("TicketCache.synchronousWrites=[{}]", config.getPersistenceConfiguration().getSynchronousWrites()); LOGGER.debug("TicketCache.timeToLive=[{}]", config.getTimeToLiveSeconds()); LOGGER.debug("TicketCache.timeToIdle=[{}]", config.getTimeToIdleSeconds()); LOGGER.debug("TicketCache.cacheManager=[{}]", this.ehcacheTicketsCache.getCacheManager().getName()); } }
@Override public CachePool createCachePool(String poolName, int cacheSize, int expiredSeconds) { CacheManager cacheManager = CacheManager.create(); Cache enCache = cacheManager.getCache(poolName); if (enCache == null) { CacheConfiguration cacheConf = cacheManager.getConfiguration() .getDefaultCacheConfiguration().clone(); cacheConf.setName(poolName); if (cacheConf.getMaxEntriesLocalHeap() != 0) { cacheConf.setMaxEntriesLocalHeap(cacheSize); } else { cacheConf.setMaxBytesLocalHeap(String.valueOf(cacheSize)); } cacheConf.setTimeToIdleSeconds(expiredSeconds); Cache cache = new Cache(cacheConf); cacheManager.addCache(cache); return new EnchachePool(poolName,cache,cacheSize); } else { return new EnchachePool(poolName,enCache,cacheSize); } }
/** * 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); }
@Override public CachePool createCachePool(String poolName, int cacheSize, int expiredSeconds) { CacheManager cacheManager = CacheManager.create(); Cache enCache = cacheManager.getCache(poolName); if (enCache == null) { CacheConfiguration cacheConf = cacheManager.getConfiguration().getDefaultCacheConfiguration().clone(); cacheConf.setName(poolName); if (cacheConf.getMaxEntriesLocalHeap() != 0) { cacheConf.setMaxEntriesLocalHeap(cacheSize); } else { cacheConf.setMaxBytesLocalHeap(String.valueOf(cacheSize)); } cacheConf.setTimeToIdleSeconds(expiredSeconds); Cache cache = new Cache(cacheConf); cacheManager.addCache(cache); return new EnchachePool(poolName, cache, cacheSize); } else { return new EnchachePool(poolName, enCache, cacheSize); } }
public static void initCache(String bucket) { if (manager == null) { load(); } if (manager.getCache(bucket) != null) { return; } CacheConfiguration config = new CacheConfiguration(bucket, 10000); //config.setDiskPersistent(false); //config.setMaxElementsOnDisk(0); //config.setMaxBytesLocalDisk(0L); config.setOverflowToOffHeap(false); PersistenceConfiguration persistenceConfiguration = new PersistenceConfiguration(); persistenceConfiguration.strategy(PersistenceConfiguration.Strategy.NONE); config.persistence(persistenceConfiguration); manager.addCache(new Cache(config)); }
public NcwmsCatalogue(NcwmsConfig config) throws IOException { super(config, new SimpleLayerNameMapper()); this.styleCatalogue = SldTemplateStyleCatalogue.getStyleCatalogue(); if (cacheManager.cacheExists(CACHE_NAME) == false) { /* * Configure cache */ CacheConfiguration cacheConfig = new CacheConfiguration(CACHE_NAME, MAX_HEAP_ENTRIES) .eternal(true) .memoryStoreEvictionPolicy(EVICTION_POLICY) .persistence(new PersistenceConfiguration().strategy(PERSISTENCE_STRATEGY)) .transactionalMode(TRANSACTIONAL_MODE); dynamicDatasetCache = new Cache(cacheConfig); cacheManager.addCache(dynamicDatasetCache); } else { dynamicDatasetCache = cacheManager.getCache(CACHE_NAME); } }
private ServletCache(String name, int type) { this.type = type; Configuration managerConfig = new Configuration(); CacheConfiguration mqCf = new CacheConfiguration(name, CacheConfig .getConfig().getMaxElementsInMemory()); mqCf.setEternal(true); DiskStoreConfiguration dsCf = new DiskStoreConfiguration(); dsCf.setPath(CacheConfig.getConfig().getDiskStorePath()); managerConfig.addDiskStore(dsCf); mqCf.setMaxElementsOnDisk(0); mqCf.setMaxEntriesLocalHeap(CacheConfig.getConfig() .getMaxElementsInMemory()); mqCf.persistence(new PersistenceConfiguration() .strategy(PersistenceConfiguration.Strategy.LOCALTEMPSWAP)); mqCf.setTransactionalMode("OFF"); mqCf.setMemoryStoreEvictionPolicy(CacheConfig.getConfig() .getMemoryStoreEvictionPolicy()); managerConfig.addCache(mqCf); cacheManager = new CacheManager(managerConfig); cache = cacheManager.getCache(name); }
/** * Create a new search cache. * * @param name a unique name for this cache, not empty * @param cacheManager the cache manager to use, not null * @param searcher the CacheSearcher to use for passing search requests to an underlying master, not null */ public EHCachingSearchCache(String name, CacheManager cacheManager, Searcher searcher) { ArgumentChecker.notNull(cacheManager, "cacheManager"); ArgumentChecker.notEmpty(name, "name"); ArgumentChecker.notNull(searcher, "searcher"); _cacheManager = cacheManager; _searcher = searcher; // Load cache configuration if (cacheManager.getCache(name + CACHE_NAME_SUFFIX) == null) { // If cache config not found, set up programmatically s_logger.warn("Could not load a cache configuration for " + name + CACHE_NAME_SUFFIX + ", building a default configuration programmatically instead"); getCacheManager().addCache(new Cache(tweakCacheConfiguration(new CacheConfiguration(name + CACHE_NAME_SUFFIX, 10000)))); } _searchRequestCache = cacheManager.getCache(name + CACHE_NAME_SUFFIX); // Async prefetch executor service ExecutorServiceFactoryBean execBean = new ExecutorServiceFactoryBean(); execBean.setNumberOfThreads(MAX_PREFETCH_CONCURRENCY); execBean.setStyle(ExecutorServiceFactoryBean.Style.CACHED); _executorService = execBean.getObjectCreating(); }
private void setupCacheSource(final boolean lazyReads, final int cacheSize, final int flushDelay) { InMemoryViewComputationCacheSource cache = new InMemoryViewComputationCacheSource(s_fudgeContext); ViewComputationCacheServer server = new ViewComputationCacheServer(cache); _serverSocket = new ServerSocketFudgeConnectionReceiver(cache.getFudgeContext(), server, Executors .newCachedThreadPool()); _serverSocket.setLazyFudgeMsgReads(lazyReads); _serverSocket.start(); _socket = new SocketFudgeConnection(cache.getFudgeContext()); _socket.setFlushDelay(flushDelay); try { _socket.setInetAddress(InetAddress.getLocalHost()); } catch (UnknownHostException e) { throw new OpenGammaRuntimeException("", e); } _socket.setPortNumber(_serverSocket.getPortNumber()); RemoteCacheClient client = new RemoteCacheClient(_socket); Configuration configuration = new Configuration(); CacheConfiguration cacheConfig = new CacheConfiguration(); cacheConfig.setMaxElementsInMemory(cacheSize); configuration.setDefaultCacheConfiguration(cacheConfig); _cacheSource = new RemoteViewComputationCacheSource(client, new DefaultFudgeMessageStoreFactory( new InMemoryBinaryDataStoreFactory(), s_fudgeContext), _cacheManager); }
@Override public Cache getCache(String id) { if (id == null) { throw new IllegalArgumentException("Cache instances require an ID"); } if (!cacheManager.cacheExists(id)) { CacheConfiguration temp = null; if (cacheConfiguration != null) { temp = cacheConfiguration.clone(); } else { // based on defaultCache temp = cacheManager.getConfiguration().getDefaultCacheConfiguration().clone(); } temp.setName(id); net.sf.ehcache.Cache cache = new net.sf.ehcache.Cache(temp); cacheManager.addCache(cache); } return new EhcacheCache(id, cacheManager.getEhcache(id)); }
@Override public Cache getCache(String id) { if (id == null) { throw new IllegalArgumentException("Cache instances require an ID"); } if (!cacheManager.cacheExists(id)) { CacheConfiguration temp = null; if (cacheConfiguration != null) { temp = cacheConfiguration.clone(); } else { // based on defaultCache temp = cacheManager.getConfiguration().getDefaultCacheConfiguration().clone(); } temp.setName(id); net.sf.ehcache.Cache cache = new net.sf.ehcache.Cache(temp); Ehcache instrumentCache = InstrumentedEhcache.instrument(registry, cache); cacheManager.addCache(instrumentCache); } return new EhcacheCache(id, cacheManager.getEhcache(id)); }
/** * Gets an EH Cache manager. * * @return the EH Cache manager. */ @Bean(destroyMethod = "shutdown") public net.sf.ehcache.CacheManager ehCacheManager() { CacheConfiguration cacheConfiguration = new CacheConfiguration(); cacheConfiguration.setName(HERD_CACHE_NAME); cacheConfiguration.setTimeToLiveSeconds(configurationHelper.getProperty(ConfigurationValue.HERD_CACHE_TIME_TO_LIVE_SECONDS, Long.class)); cacheConfiguration.setTimeToIdleSeconds(configurationHelper.getProperty(ConfigurationValue.HERD_CACHE_TIME_TO_IDLE_SECONDS, Long.class)); cacheConfiguration.setMaxElementsInMemory(configurationHelper.getProperty(ConfigurationValue.HERD_CACHE_MAX_ELEMENTS_IN_MEMORY, Integer.class)); cacheConfiguration.setMemoryStoreEvictionPolicy(configurationHelper.getProperty(ConfigurationValue.HERD_CACHE_MEMORY_STORE_EVICTION_POLICY)); net.sf.ehcache.config.Configuration config = new net.sf.ehcache.config.Configuration(); config.addCache(cacheConfiguration); return net.sf.ehcache.CacheManager.create(config); }
private CacheManager getCacheManager() { if (manager == null) { Configuration config = new Configuration(); CacheConfiguration cacheconfig = new CacheConfiguration(getName(), maxElementsInMemory); cacheconfig.setDiskExpiryThreadIntervalSeconds(diskExpiryThreadIntervalSeconds); cacheconfig.setDiskPersistent(diskPersistent); cacheconfig.setEternal(eternal); cacheconfig.setMaxElementsOnDisk(maxElementsOnDisk); cacheconfig.setMemoryStoreEvictionPolicyFromObject(memoryStoreEvictionPolicy); cacheconfig.setOverflowToDisk(overflowToDisk); cacheconfig.setTimeToIdleSeconds(timeToIdleSeconds); cacheconfig.setTimeToLiveSeconds(timeToLiveSeconds); DiskStoreConfiguration diskStoreConfigurationParameter = new DiskStoreConfiguration(); diskStoreConfigurationParameter.setPath(getPath().getAbsolutePath()); config.addDiskStore(diskStoreConfigurationParameter); config.setDefaultCacheConfiguration(cacheconfig); manager = new CacheManager(config); } return manager; }
/** * Load cache. * * @param name the name * @return the cache configuration */ private CacheConfiguration loadCache(String name) { CacheConfiguration cacheConfiguration = new CacheConfiguration(); cacheConfiguration.setMemoryStoreEvictionPolicy("LRU"); cacheConfiguration.setMaxEntriesLocalHeap(10000); cacheConfiguration.setMaxEntriesLocalDisk(1000000); if (debug) { cacheConfiguration.setTimeToIdleSeconds(1); cacheConfiguration.setTimeToLiveSeconds(2); } else { cacheConfiguration.setTimeToIdleSeconds(10); cacheConfiguration.setTimeToLiveSeconds(20); } cacheConfiguration.setName(name); return cacheConfiguration; }
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 String buildConfiguration(Object cache) { final StringBuilder sb = new StringBuilder(); // getCacheConfiguration() et getMaxElementsOnDisk() n'existent pas en ehcache 1.2 final CacheConfiguration config = ((Ehcache) cache).getCacheConfiguration(); sb.append("ehcache [maxElementsInMemory = ").append(config.getMaxElementsInMemory()); final boolean overflowToDisk = config.isOverflowToDisk(); sb.append(", overflowToDisk = ").append(overflowToDisk); if (overflowToDisk) { sb.append(", maxElementsOnDisk = ").append(config.getMaxElementsOnDisk()); } final boolean eternal = config.isEternal(); sb.append(", eternal = ").append(eternal); if (!eternal) { sb.append(", timeToLiveSeconds = ").append(config.getTimeToLiveSeconds()); sb.append(", timeToIdleSeconds = ").append(config.getTimeToIdleSeconds()); sb.append(", memoryStoreEvictionPolicy = ") .append(config.getMemoryStoreEvictionPolicy()); } sb.append(", diskPersistent = ").append(config.isDiskPersistent()); sb.append(']'); return sb.toString(); }
private synchronized static Cache getEHCache(String cacheName, CacheType type) { CacheManager mgr = getEHCacheManager(); cacheName = type.getCacheName(cacheName); Cache ret = mgr.getCache(cacheName); if (ret == null) { // create new cache by cloning from the appropriate cache CacheConfiguration config = null; if (type == CacheType.CUSTOM) { throw new IllegalStateException("CacheName: " + cacheName + ", does not exist in ehcache.xml"); } else if (type == CacheType.SESSION_MEMORY) { config = mgr.getCache("CacheMgrSess").getCacheConfiguration().clone(); } else if (type == CacheType.DISK) { config = mgr.getCache("CacheMgrDisk").getCacheConfiguration().clone(); } else { config = mgr.getCache("CacheMgrMem").getCacheConfiguration().clone(); } config.setName(cacheName); ret = new Cache(config); mgr.addCache(ret); } return ret; }
@Override protected Cache getMissingCache(final String name) { final Cache missingCache = super.getMissingCache(name); if (missingCache == null) { final CacheConfiguration cacheConfiguration = defaults.clone().name(name); final String cacheName = getCacheName(name); if (cacheExpires.containsKey(cacheName)) { cacheConfiguration.setTimeToLiveSeconds(cacheExpires.get(cacheName)); } final net.sf.ehcache.Cache ehcache = new net.sf.ehcache.Cache(cacheConfiguration); ehcache.initialise(); return new EhCacheCache(ehcache); } else { return missingCache; } }
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; }
/** * Inits the cache ehcache big memory. */ @SuppressWarnings("deprecation") private static void initCacheEhcacheBigMemory() { // Create a CacheManager using defaults sEhcacheManager = CacheManager.create(); // Create a Cache specifying its configuration. sEhcacheCache = new Cache(new CacheConfiguration("test", 10000) .memoryStoreEvictionPolicy(MemoryStoreEvictionPolicy.LRU) .overflowToDisk(false).eternal(false).timeToLiveSeconds(6000) .timeToIdleSeconds(6000).diskPersistent(false) .diskExpiryThreadIntervalSeconds(0).overflowToOffHeap(true) .maxMemoryOffHeap(sBigMemorySize)); sEhcacheManager.addCache(sEhcacheCache); }
/** * Inits the cache ehcache. */ @SuppressWarnings("deprecation") private static void initCacheEhcache() { // Create a CacheManager using defaults sEhcacheManager = CacheManager.create(); // Create a Cache specifying its configuration. sEhcacheCache = new Cache(new CacheConfiguration("test", (int) sCacheItemsLimit).memoryStoreEvictionPolicy( MemoryStoreEvictionPolicy.LRU).overflowToDisk(false).eternal( false).timeToLiveSeconds(6000).timeToIdleSeconds(6000) .diskPersistent(false).diskExpiryThreadIntervalSeconds(0)); sEhcacheManager.addCache(sEhcacheCache); }
/** * Create the cache to be used for storing results. */ protected void createCache() { LOG.info("Creating EHCache: " + getCacheName()); cacheManager = CacheManager.getInstance(); /** Only create the cache once per VM **/ if (cacheManager.cacheExists(getCacheName())) { return; } cacheManager.addCache(getCacheName()); CacheConfiguration config = this.getCache().getCacheConfiguration(); LOG.info("--> MaxEntriesLocalDisk:" + config.getMaxEntriesLocalDisk()); LOG.info("--> MaxEntriesLocalHeap:" + config.getMaxEntriesLocalHeap()); LOG.info("--> TimeToIdleSeconds:" + config.getTimeToIdleSeconds()); LOG.info("--> TimeToLiveSeconds:" + config.getTimeToLiveSeconds()); }
/** * Read cache config from the file caches.dat * * @param strCacheName * The cache name * @return The config */ private CacheConfiguration getCacheConfiguration( String strCacheName ) { CacheConfiguration config = new CacheConfiguration( ); config.setName( strCacheName ); config.setMaxElementsInMemory( getIntProperty( strCacheName, PROPERTY_MAX_ELEMENTS, _nDefaultMaxElementsInMemory ) ); config.setEternal( getBooleanProperty( strCacheName, PROPERTY_ETERNAL, _bDefaultEternal ) ); config.setTimeToIdleSeconds( getLongProperty( strCacheName, PROPERTY_TIME_TO_IDLE, _lDefaultTimeToIdle ) ); config.setTimeToLiveSeconds( getLongProperty( strCacheName, PROPERTY_TIME_TO_LIVE, _lDefaultTimeToLive ) ); config.setOverflowToDisk( getBooleanProperty( strCacheName, PROPERTY_OVERFLOW_TO_DISK, _bDefaultOverflowToDisk ) ); config.setDiskPersistent( getBooleanProperty( strCacheName, PROPERTY_DISK_PERSISTENT, _bDefaultDiskPersistent ) ); config.setDiskExpiryThreadIntervalSeconds( getLongProperty( strCacheName, PROPERTY_DISK_EXPIRY, _lDefaultDiskExpiry ) ); config.setMaxElementsOnDisk( getIntProperty( strCacheName, PROPERTY_MAX_ELEMENTS_DISK, _nDefaultMaxElementsOnDisk ) ); config.setStatistics( getBooleanProperty( strCacheName, PROPERTY_STATISTICS, _bDefaultStatistics ) ); return config; }
public static Cache createMemCache(String name , long maxEntriesLocalHeap, long timeToLiveSeconds, long timeToIdleSeconds){ CacheConfiguration config = new CacheConfiguration(); config.setName(name); config.setEternal(false); config.setMaxEntriesLocalHeap(maxEntriesLocalHeap); config.setTimeToLiveSeconds(timeToLiveSeconds); config.setTimeToIdleSeconds(timeToIdleSeconds); config.setCopyOnRead(false); config.setCopyOnWrite(true); config.setMemoryStoreEvictionPolicy("LRU"); CopyStrategyConfiguration copyConfig = new CopyStrategyConfiguration(); copyConfig.setClass("org.cam.core.cache.CloneCopyStrategy"); config.addCopyStrategy(copyConfig); PersistenceConfiguration persistConfig = new PersistenceConfiguration(); persistConfig.setStrategy("NONE"); config.addPersistence(persistConfig); return new Cache(config); }
public void add(Query query) { String name = query.getQid().getId(); if (!this.manager.cacheExists(name) && query.isCacheable()) { CacheConfiguration config = defaultConfig.clone(); config.setName(name); config.setEternal(query.isEternal()); config.setTimeToLiveSeconds(query.getCacheTime()); Cache c = new Cache(config); this.manager.addCache(c); if (log.isDebugEnabled()) { log.debug(String.format("Cache %s created: eternal = %s, cacheTime = %d", c.getName(), query.isEternal(), query.getCacheTime())); } } }
private void configureCache() { CacheManager singletonManager; try { InputStream inputStream = this.getClass().getResourceAsStream("/ehcache.xml"); singletonManager = CacheManager.newInstance(inputStream); } catch (Exception e) { singletonManager = CacheManager.create(); singletonManager.addCache(CACHE_NAME); cache.getCacheConfiguration(); cache = singletonManager.getCache(CACHE_NAME); CacheConfiguration cacheConfiguration = cache.getCacheConfiguration(); cacheConfiguration.setTimeToIdleSeconds(300); cacheConfiguration.setTimeToLiveSeconds(300); e.printStackTrace(); } cache = singletonManager.getCache(CACHE_NAME); }
public LocalCacheManager(String name, int max, int exptime, boolean copyOnRead, boolean copyOnWrite) { this.cache = CacheManager.getInstance().getCache(name); if (cache == null) { CacheConfiguration config = new CacheConfiguration(name, max) .copyOnRead(copyOnRead) .copyOnWrite(copyOnWrite) .memoryStoreEvictionPolicy(MemoryStoreEvictionPolicy.LRU) .eternal(false) .timeToLiveSeconds(exptime) .timeToIdleSeconds(exptime) .diskExpiryThreadIntervalSeconds(60) .persistence(new PersistenceConfiguration().strategy(PersistenceConfiguration.Strategy.NONE)); this.cache = new Cache(config, null, null); CacheManager.getInstance().addCache(cache); if (logger.isInfoEnabled()) { logger.info("Arcus k/v local cache is enabled : %s", cache.toString()); } } }
@Test public void bootstrapCacheLoaderFactory() { Config config = ConfigFactory .empty() .withValue("bootstrapCacheLoaderFactory.class", fromAnyRef("net.sf.ehcache.distribution.RMIBootstrapCacheLoaderFactory")) .withValue("bootstrapCacheLoaderFactory.bootstrapAsynchronously", fromAnyRef(true)) .withValue("bootstrapCacheLoaderFactory.maximumChunkSizeBytes", fromAnyRef(5000000)); CacheConfigurationBuilder builder = new CacheConfigurationBuilder("c1"); CacheConfiguration cache = builder.build(config); BootstrapCacheLoaderFactoryConfiguration bootstrapCacheLoader = cache .getBootstrapCacheLoaderFactoryConfiguration(); assertEquals("net.sf.ehcache.distribution.RMIBootstrapCacheLoaderFactory", bootstrapCacheLoader.getFullyQualifiedClassPath()); assertEquals("bootstrapAsynchronously=true;maximumChunkSizeBytes=5000000", bootstrapCacheLoader.getProperties()); }
@Test public void cacheDecoratorFactories() { Config config = ConfigFactory .empty() .withValue("cacheDecoratorFactory.blocking.class", fromAnyRef(BlockingCache.class.getName())) .withValue("cacheDecoratorFactory.blocking.p1", fromAnyRef(BlockingCache.class.getName())) .withValue("cacheDecoratorFactory.readT.class", fromAnyRef(ReadThroughCache.class.getName())); CacheConfigurationBuilder builder = new CacheConfigurationBuilder("c1"); CacheConfiguration cache = builder.build(config); List<CacheDecoratorFactoryConfiguration> decorators = cache.getCacheDecoratorConfigurations(); assertEquals(2, decorators.size()); assertEquals(BlockingCache.class.getName(), decorators.get(0).getFullyQualifiedClassPath()); assertEquals(ReadThroughCache.class.getName(), decorators.get(1).getFullyQualifiedClassPath()); }