public CacheConfigurationBuilder(final String name) { this.path = "ehcache.cache." + name; this.cache = new CacheConfiguration(); cache.setName(name); }
@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(); } }
/** * Builder to set the name of the cache. * <p> * Cache names have constraints on the characters they can use: * <ul> * <li>the '/' character is illegal,</li> * <li>the '#' character does not work with RMI replication,</li> * <li>caches that are registered as MBeans must obey the {@link javax.management.ObjectName} rules for unquoted value. * This means the following characters are illegal: ',', '=', ':', '"', '*' and '?'.</li> * </ul> * Note that caches inside a clustered cache manager are by default registered as MBean. * * @param name the cache name. This must be unique. * @return this configuration instance * @see #setName(String) */ public final CacheConfiguration name(String name) { setName(name); return this; }
/** * Sets the cache name which will name. * * @param name the name of the cache. Should not be null. Should also not contain any '/' characters, as these interfere * with distribution * @throws IllegalArgumentException if an illegal name is used. */ public final void setName(String name) throws IllegalArgumentException { if (!cacheStatus.isUninitialized()) { throw new IllegalStateException("Only uninitialised caches can have their names set."); } configuration.setName(name); }
/** * Builder to set the name of the cache. * * @param name the cache name. This must be unique. The / character is illegal. The # character does not work with RMI replication. * @return this configuration instance * @see #setName(String) */ public final CacheConfiguration name(String name) { setName(name); return this; }
/** * Builder to set the name of the cache. * * @param name the cache name. This must be unique. The / character is illegal. The # character does not work with RMI replication. * @return this configuration instance * @see #setName(String) */ public final CacheConfiguration name(String name) { setName(name); return this; }
private Cache addCache(Class<?> cacheClazz) { // get the default (template) cache configuration CacheConfiguration cacheConfiguration = getCacheManager().getConfiguration().getDefaultCacheConfiguration(); // give it a unique name or the process will fail cacheConfiguration.setName(cacheClazz.getName()); Cache newCache = new Cache(cacheConfiguration); getCacheManager().addCache(newCache); return newCache; }
public CacheConfigurationBuilder(final String name) { this.path = "ehcache.cache." + name; this.cache = new CacheConfiguration(); cache.setName(name); }
/** * Sets the cache name which will name. * * @param name the name of the cache. Should not be null. Should also not contain any '/' characters, as these interfere * with distribution * @throws IllegalArgumentException if an illegal name is used. */ public final void setName(String name) throws IllegalArgumentException { if (!cacheStatus.isUninitialized()) { throw new IllegalStateException("Only uninitialised caches can have their names set."); } configuration.setName(name); }
/** * Sets the cache name which will name. * * @param name the name of the cache. Should not be null. Should also not contain any '/' characters, as these interfere * with distribution * @throws IllegalArgumentException if an illegal name is used. */ public final void setName(String name) throws IllegalArgumentException { if (!cacheStatus.isUninitialized()) { throw new IllegalStateException("Only uninitialised caches can have their names set."); } configuration.setName(name); }
/** * Sets the cache name which will name. * * @param name the name of the cache. Should not be null. Should also not contain any '/' characters, as these interfere * with distribution * @throws IllegalArgumentException if an illegal name is used. */ public final void setName(String name) throws IllegalArgumentException { if (!cacheStatus.isUninitialized()) { throw new IllegalStateException("Only uninitialised caches can have their names set."); } configuration.setName(name); }
private CacheConfiguration newCache(final String name) { try { final CacheConfiguration c; c = mgr.getDefaultCacheConfiguration().clone(); c.setName(name); return c; } catch (CloneNotSupportedException e) { throw new ProvisionException("Cannot configure cache " + name, e); } } }
private CacheConfiguration newCache(final String name) { try { final CacheConfiguration c; c = mgr.getDefaultCacheConfiguration().clone(); c.setName(name); return c; } catch (CloneNotSupportedException e) { throw new ProvisionException("Cannot configure cache " + name, e); } } }
public static CacheConfiguration getCacheConfiguration(String key, CacheManager cacheManager) { CacheConfiguration cc = cacheManager.getConfiguration().getCacheConfigurations().get(key); if (cc == null && key.contains("-")) { cc = cacheManager.getConfiguration().getCacheConfigurations().get( key.substring(0, key.lastIndexOf('-') - 1)); } if (cc == null) { cc = cacheManager.getConfiguration().getDefaultCacheConfiguration(); } if (cc == null) { cc = new CacheConfiguration(); } else { cc = cc.clone(); } cc.setName(key); return cc; }
public static CacheConfiguration getCacheConfiguration(String key, CacheManager cacheManager) { CacheConfiguration cc = cacheManager.getConfiguration().getCacheConfigurations().get(key); if (cc == null && key.contains("-")) { cc = cacheManager.getConfiguration().getCacheConfigurations().get( key.substring(0, key.lastIndexOf('-') - 1)); } if (cc == null) { cc = cacheManager.getConfiguration().getDefaultCacheConfiguration(); } if (cc == null) { cc = new CacheConfiguration(); } else { cc = cc.clone(); } cc.setName(key); return cc; }
/** * Gets the cache with the given name from Ehache. * <p> * If no cache with that name exists, one will be created and registered, using the configuration from the cache * with the given template name. */ private static net.sf.ehcache.Cache getCache(CacheManager embeddedCacheManager, String cacheName, String templateName) { net.sf.ehcache.Cache cache = embeddedCacheManager.getCache( cacheName ); if ( cache == null ) { CacheConfiguration configuration = embeddedCacheManager.getConfiguration().getCacheConfigurations().get( templateName ).clone(); configuration.setName( cacheName ); cache = new net.sf.ehcache.Cache( configuration ); embeddedCacheManager.addCache( cache ); } return cache; }
public static CacheConfiguration getCacheConfiguration(String key, CacheManager cacheManager) { CacheConfiguration cc = cacheManager.getConfiguration().getCacheConfigurations().get(key); if (cc == null && key.contains("-")) { cc = cacheManager.getConfiguration().getCacheConfigurations().get( key.substring(0, key.lastIndexOf('-'))); } if (cc == null) { cc = cacheManager.getConfiguration().getDefaultCacheConfiguration(); } if (cc == null) { cc = new CacheConfiguration(); } else { cc = (CacheConfiguration)cc.clone(); } cc.setName(key); return cc; }
@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); }
@Override protected void doStart() throws Exception { super.doStart(); cacheManager = new CacheManager(); CacheConfiguration configuration = new CacheConfiguration(); configuration.setEternal(false); configuration.setTimeToIdleSeconds(configuration().getTimeToIdleSeconds()); configuration.setTimeToLiveSeconds(configuration().getTimeToLiveSeconds()); configuration.setMaxEntriesLocalHeap(configuration().getMaxEntriesLocalHeap()); configuration.setName(configuration().getName()); LOGGER.info("Create a new cache: {}", configuration().getName()); net.sf.ehcache.Cache ehCache = new net.sf.ehcache.Cache(configuration); cache = new EhCacheDelegate(ehCache); cacheManager.addCache(ehCache); }
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; }