/** * Set the disk spool buffer size (in MB). * @see #setDiskSpoolBufferSizeMB(int) */ public void setDiskSpoolBufferSize(int diskSpoolBufferSize) { setDiskSpoolBufferSizeMB(diskSpoolBufferSize); }
/** * Set the time to live. * @see #setTimeToLiveSeconds(long) */ public void setTimeToLive(int timeToLive) { setTimeToLiveSeconds(timeToLive); }
/** * Set the time to idle. * @see #setTimeToIdleSeconds(long) */ public void setTimeToIdle(int timeToIdle) { setTimeToIdleSeconds(timeToIdle); }
@Test public void testEhCacheFactoryBeanWithBlockingCache() { EhCacheManagerFactoryBean cacheManagerFb = new EhCacheManagerFactoryBean(); cacheManagerFb.afterPropertiesSet(); try { CacheManager cm = cacheManagerFb.getObject(); EhCacheFactoryBean cacheFb = new EhCacheFactoryBean(); cacheFb.setCacheManager(cm); cacheFb.setCacheName("myCache1"); cacheFb.setBlocking(true); assertEquals(cacheFb.getObjectType(), BlockingCache.class); cacheFb.afterPropertiesSet(); Ehcache myCache1 = cm.getEhcache("myCache1"); assertTrue(myCache1 instanceof BlockingCache); } finally { cacheManagerFb.destroy(); } }
@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(); }
@Override public void afterPropertiesSet() { if (getCacheManager() == null) { setCacheManager(EhCacheManagerUtils.buildCacheManager()); } super.afterPropertiesSet(); }
@Override protected Cache getMissingCache(String name) { net.sf.ehcache.CacheManager cacheManager = getCacheManager(); Assert.state(cacheManager != null, "No CacheManager set"); // Check the EhCache cache again (in case the cache was added at runtime) Ehcache ehcache = cacheManager.getEhcache(name); if (ehcache != null) { return new EhCacheCache(ehcache); } return null; }
public EhCacheFactoryBean() { setMaxEntriesLocalHeap(10000); setMaxEntriesLocalDisk(10000000); setTimeToLiveSeconds(120); setTimeToIdleSeconds(120); }
@Override @Nullable public ValueWrapper get(Object key) { Element element = lookup(key); return toValueWrapper(element); }
/** * Build an EhCache {@link CacheManager} from the given configuration resource. * @param configLocation the location of the configuration file (as a Spring resource) * @return the new EhCache CacheManager * @throws CacheException in case of configuration parsing failure */ public static CacheManager buildCacheManager(Resource configLocation) throws CacheException { return new CacheManager(parseConfiguration(configLocation)); }
private <T> T loadValue(Object key, Callable<T> valueLoader) { T value; try { value = valueLoader.call(); } catch (Throwable ex) { throw new ValueRetrievalException(key, valueLoader, ex); } put(key, value); return value; }
@Override @Nullable public ValueWrapper putIfAbsent(Object key, @Nullable Object value) { Element existingElement = this.cache.putIfAbsent(new Element(key, value)); return toValueWrapper(existingElement); }
/** * Set a name for which to retrieve or create a cache instance. * Default is the bean name of this EhCacheFactoryBean. */ public void setCacheName(String cacheName) { setName(cacheName); }
@Test public void testEhCacheFactoryBeanWithExplicitCacheManager() { doTestEhCacheFactoryBean(true); }
public EhCacheFactoryBean() { setMaxEntriesLocalHeap(10000); setMaxEntriesLocalDisk(10000000); setTimeToLiveSeconds(120); setTimeToIdleSeconds(120); }
/** * Set the disk spool buffer size (in MB). * @see #setDiskSpoolBufferSizeMB(int) */ public void setDiskSpoolBufferSize(int diskSpoolBufferSize) { setDiskSpoolBufferSizeMB(diskSpoolBufferSize); }
/** * Set the time to idle. * @see #setTimeToIdleSeconds(long) */ public void setTimeToIdle(int timeToIdle) { setTimeToIdleSeconds(timeToIdle); }
/** * Build an EhCache {@link CacheManager} from the given configuration resource. * @param name the desired name of the cache manager * @param configLocation the location of the configuration file (as a Spring resource) * @return the new EhCache CacheManager * @throws CacheException in case of configuration parsing failure */ public static CacheManager buildCacheManager(String name, Resource configLocation) throws CacheException { Configuration configuration = parseConfiguration(configLocation); configuration.setName(name); return new CacheManager(configuration); }
/** * Set a name for which to retrieve or create a cache instance. * Default is the bean name of this EhCacheFactoryBean. */ public void setCacheName(String cacheName) { setName(cacheName); }
@Test public void testEhCacheFactoryBeanWithDefaultCacheManager() { doTestEhCacheFactoryBean(false); }