public ConfigurationBuilder() { this.eh = new Configuration(); }
@Bean(name = "goCache") public GoCache createCache() { CacheManager cacheManager = CacheManager.newInstance(new Configuration().name(getClass().getName())); Cache cache = new Cache(cacheConfiguration); cacheManager.addCache(cache); return new GoCache(cache, transactionSynchronizationManager); }
private static Ehcache createCacheIfRequired() { final CacheManager instance = CacheManager.newInstance(new Configuration().name(CachingSubjectDnX509PrincipalExtractor.class.getName())); synchronized (instance) { if (!instance.cacheExists(CACHE_NAME)) { instance.addCache(new Cache(cacheConfiguration())); } return instance.getCache(CACHE_NAME); } }
private static Ehcache createCacheIfRequired(String cacheName) { final CacheManager instance = CacheManager.newInstance(new Configuration().name(cacheName)); synchronized (instance) { if (!instance.cacheExists(cacheName)) { instance.addCache(new net.sf.ehcache.Cache(cacheConfiguration(cacheName))); } return instance.getCache(cacheName); } }
private static Ehcache createCacheIfRequired(String cacheName) { final CacheManager instance = CacheManager.newInstance(new Configuration().name(cacheName)); synchronized (instance) { if (!instance.cacheExists(cacheName)) { instance.addCache(new Cache(cacheConfiguration(cacheName))); } return instance.getCache(cacheName); } }
@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(); } }
@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); }
@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(); }
System.out.println("runtime used memory: " + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1024 / 1024 + "M"); Configuration conf = new Configuration(); conf.setMaxBytesLocalHeap("100M"); CacheManager cacheManager = CacheManager.create(conf);
/** * Configures a bean from an XML input stream. */ public static Configuration parseConfiguration(final InputStream inputStream) throws CacheException { LOG.debug("Configuring ehcache from InputStream"); Configuration configuration = new Configuration(); try { InputStream translatedInputStream = translateSystemProperties(inputStream); final SAXParser parser = SAXParserFactory.newInstance().newSAXParser(); final BeanHandler handler = new BeanHandler(configuration); parser.parse(translatedInputStream, handler); } catch (Exception e) { throw new CacheException("Error configuring from input stream. Initial cause was " + e.getMessage(), e); } configuration.setSource(ConfigurationSource.getConfigurationSource(inputStream)); return configuration; }
public ConfigurationBuilder() { this.eh = new Configuration(); }
/** * Configures a bean from an XML input stream. */ public static Configuration parseConfiguration(final InputStream inputStream) throws CacheException { LOG.debug("Configuring ehcache from InputStream"); Configuration configuration = new Configuration(); try { InputStream translatedInputStream = translateSystemProperties(inputStream); final SAXParser parser = SAXParserFactory.newInstance().newSAXParser(); final BeanHandler handler = new BeanHandler(configuration); parser.parse(translatedInputStream, handler); } catch (Exception e) { throw new CacheException("Error configuring from input stream. Initial cause was " + e.getMessage(), e); } configuration.setSource(ConfigurationSource.getConfigurationSource(inputStream)); return configuration; }
/** * Configures a bean from an XML input stream. */ public static Configuration parseConfiguration(final InputStream inputStream) throws CacheException { LOG.debug("Configuring ehcache from InputStream"); Configuration configuration = new Configuration(); try { InputStream translatedInputStream = translateSystemProperties(inputStream); final SAXParser parser = SAXParserFactory.newInstance().newSAXParser(); final BeanHandler handler = new BeanHandler(configuration); parser.parse(translatedInputStream, handler); } catch (Exception e) { throw new CacheException("Error configuring from input stream. Initial cause was " + e.getMessage(), e); } configuration.setSource(ConfigurationSource.getConfigurationSource(inputStream)); return configuration; }
/** * Configures a bean from an XML input stream. */ public static Configuration parseConfiguration(final InputStream inputStream) throws CacheException { LOG.debug("Configuring ehcache from InputStream"); Configuration configuration = new Configuration(); try { InputStream translatedInputStream = translateSystemProperties(inputStream); final SAXParser parser = SAXParserFactory.newInstance().newSAXParser(); final BeanHandler handler = new BeanHandler(configuration); parser.parse(translatedInputStream, handler); } catch (Exception e) { throw new CacheException("Error configuring from input stream. Initial cause was " + e.getMessage(), e); } configuration.setSource(ConfigurationSource.getConfigurationSource(inputStream)); return configuration; }
protected void buildCacheManagerWithDefaultConfiguration() throws SCacheException { if (cacheManager != null) { String message = "Unable to build a new Cache Manager as the existing one is still alive: " + cacheManager + ". "; if (logger.isLoggable(this.getClass(), TechnicalLogSeverity.TRACE)) { message += ". Last creation was: \n" + cacheManagerLastCreation; } throw new SCacheException(message); } final Configuration configuration = new Configuration(); configuration.setDefaultCacheConfiguration(defaultCacheConfiguration); configuration.diskStore(new DiskStoreConfiguration().path(diskStorePath)); cacheManager = new CacheManager(configuration); if (logger.isLoggable(this.getClass(), TechnicalLogSeverity.TRACE)) { cacheManagerLastCreation = getCacheManagerCreationDetails(); } }
@Bean(destroyMethod = "shutdown") public net.sf.ehcache.CacheManager ehCacheManager() { CacheConfiguration cacheConfiguration = new CacheConfiguration(); cacheConfiguration.setName("restApiAuthTokenCache"); cacheConfiguration.setMemoryStoreEvictionPolicy("LRU"); cacheConfiguration.setMaxEntriesLocalHeap(0); // 0 = MAX cacheConfiguration.setTimeToLiveSeconds(14400); // 4 hours. cacheConfiguration.setEternal(false); net.sf.ehcache.config.Configuration config = new net.sf.ehcache.config.Configuration(); config.addCache(cacheConfiguration); return net.sf.ehcache.CacheManager.newInstance(config); }
protected void buildCacheManagerWithDefaultConfiguration() throws SCacheException { if (cacheManager != null) { String message = "Unable to build a new Cache Manager as the existing one is still alive: " + cacheManager + ". "; if (logger.isLoggable(this.getClass(), TechnicalLogSeverity.TRACE)) { message += ". Last creation was: \n" + cacheManagerLastCreation; } throw new SCacheException(message); } final Configuration configuration = new Configuration(); configuration.setDefaultCacheConfiguration(defaultCacheConfiguration); configuration.diskStore(new DiskStoreConfiguration().path(diskStorePath)); cacheManager = new CacheManager(configuration); if (logger.isLoggable(this.getClass(), TechnicalLogSeverity.TRACE)) { cacheManagerLastCreation = getCacheManagerCreationDetails(); } }
private CacheManager createCacheManager(String diskStorePath) { Configuration cacheManagerConfig = new Configuration().dynamicConfig(false) .diskStore( new DiskStoreConfiguration().path(diskStorePath)) .name("default") .updateCheck(false); return CacheManager.create(cacheManagerConfig); }
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); }
/** * 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); }