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); }
private Ehcache buildCache(final TicketDefinition ticketDefinition) { val cache = casProperties.getTicket().getRegistry().getEhcache(); val configExists = ResourceUtils.doesResourceExist(cache.getConfigLocation()); val ehcacheProperties = casProperties.getTicket().getRegistry().getEhcache(); val bean = new EhCacheFactoryBean(); bean.setCacheName(ticketDefinition.getProperties().getStorageName()); LOGGER.debug("Constructing Ehcache cache [{}]", bean.getName()); if (configExists) { bean.setCacheEventListeners(CollectionUtils.wrapSet(ticketRMISynchronousCacheReplicator())); bean.setBootstrapCacheLoader(ticketCacheBootstrapCacheLoader()); } else { LOGGER.warn("In registering ticket definition [{}], Ehcache configuration file [{}] cannot be found " + "so no cache event listeners will be configured to bootstrap. " + "The ticket registry will operate in standalone mode", ticketDefinition.getPrefix(), cache.getConfigLocation()); } bean.setTimeToIdle((int) ticketDefinition.getProperties().getStorageTimeout()); bean.setTimeToLive((int) ticketDefinition.getProperties().getStorageTimeout()); bean.setDiskExpiryThreadIntervalSeconds(ehcacheProperties.getDiskExpiryThreadIntervalSeconds()); bean.setEternal(ehcacheProperties.isEternal()); bean.setMaxEntriesLocalHeap(ehcacheProperties.getMaxElementsInMemory()); bean.setMaxEntriesInCache(ehcacheProperties.getMaxElementsInCache()); bean.setMaxEntriesLocalDisk(ehcacheProperties.getMaxElementsOnDisk()); bean.setMemoryStoreEvictionPolicy(ehcacheProperties.getMemoryStoreEvictionPolicy()); val c = new PersistenceConfiguration(); c.strategy(ehcacheProperties.getPersistence()); c.setSynchronousWrites(ehcacheProperties.isSynchronousWrites()); bean.persistence(c); bean.afterPropertiesSet(); return bean.getObject(); }
boolean cacheManagerFbInitialized = false; try { EhCacheFactoryBean cacheFb = new EhCacheFactoryBean(); Class<? extends Ehcache> objectType = cacheFb.getObjectType(); assertTrue(Ehcache.class.isAssignableFrom(objectType)); assertTrue("Singleton property", cacheFb.isSingleton()); if (useCacheManagerFb) { cacheManagerFb = new EhCacheManagerFactoryBean(); cacheManagerFb.afterPropertiesSet(); cacheManagerFbInitialized = true; cacheFb.setCacheManager(cacheManagerFb.getObject()); cacheFb.setCacheName("myCache1"); cacheFb.afterPropertiesSet(); cache = (Cache) cacheFb.getObject(); Class<? extends Ehcache> objectType2 = cacheFb.getObjectType(); assertSame(objectType, objectType2); CacheConfiguration config = cache.getCacheConfiguration(); cacheFb = new EhCacheFactoryBean(); if (useCacheManagerFb) { cacheFb.setCacheManager(cacheManagerFb.getObject()); cacheFb.setCacheName("undefinedCache"); cacheFb.afterPropertiesSet(); cache = (Cache) cacheFb.getObject(); config = cache.getCacheConfiguration(); assertEquals("undefinedCache", cache.getName());
@Override public void afterPropertiesSet() throws CacheException { String cacheName = getName(); if (cacheName == null) { cacheName = this.beanName; if (cacheName != null) { setName(cacheName); logger.debug("Creating new EhCache cache region '" + cacheName + "'"); rawCache = createCache(); rawCache.setBootstrapCacheLoader(this.bootstrapCacheLoader); Ehcache decoratedCache = decorateCache(rawCache); if (decoratedCache != rawCache) { this.cacheManager.replaceCacheWithDecoratedCache(rawCache, decoratedCache);
@Test public void testEhCacheFactoryBeanWithSelfPopulatingCache() { EhCacheManagerFactoryBean cacheManagerFb = new EhCacheManagerFactoryBean(); cacheManagerFb.afterPropertiesSet(); try { CacheManager cm = cacheManagerFb.getObject(); EhCacheFactoryBean cacheFb = new EhCacheFactoryBean(); cacheFb.setCacheManager(cm); cacheFb.setCacheName("myCache1"); cacheFb.setCacheEntryFactory(key -> key); assertEquals(cacheFb.getObjectType(), SelfPopulatingCache.class); cacheFb.afterPropertiesSet(); Ehcache myCache1 = cm.getEhcache("myCache1"); assertTrue(myCache1 instanceof SelfPopulatingCache); assertEquals("myKey1", myCache1.get("myKey1").getObjectValue()); } finally { cacheManagerFb.destroy(); } }
@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(); } }
@Override public void afterPropertiesSet() throws CacheException { String cacheName = getName(); if (cacheName == null) { cacheName = this.beanName; logger.debug("Creating new EhCache cache region '" + cacheName + "'"); rawCache = createCache(); rawCache.setBootstrapCacheLoader(this.bootstrapCacheLoader); Ehcache decoratedCache = decorateCache(rawCache); if (decoratedCache != rawCache) { this.cacheManager.replaceCacheWithDecoratedCache(rawCache, decoratedCache);
/** * Set the time to idle. * @see #setTimeToIdleSeconds(long) */ public void setTimeToIdle(int timeToIdle) { setTimeToIdleSeconds(timeToIdle); }
@SuppressWarnings("deprecation") public EhCacheFactoryBean() { setMaxEntriesLocalHeap(10000); setMaxElementsOnDisk(10000000); setTimeToLiveSeconds(120); setTimeToIdleSeconds(120); }
@Override protected Ehcache decorateCache(Ehcache cache) { Ehcache decorated = super.decorateCache(cache); if (decorated instanceof BlockingCache) { ((BlockingCache) decorated).setTimeoutMillis(timeoutMillis); } return decorated; } }
@Override public Ehcache getObject() { Ehcache cache = (Ehcache) super.getObject(); registerAll(cache, cacheListeners); return cache; }
public Ehcache createCache(CacheEventListener... listeners) { try { super.afterPropertiesSet(); Ehcache cache = (Ehcache) getObject(); registerAll(cache, listeners); return cache; } catch (Exception e) { throw new RuntimeException("Could not create cache", e); } }
@Override public void afterPropertiesSet() throws CacheException { String cacheName = getName(); if (cacheName == null) { cacheName = this.beanName; if (cacheName != null) { setName(cacheName); logger.debug("Creating new EhCache cache region '" + cacheName + "'"); rawCache = createCache(); rawCache.setBootstrapCacheLoader(this.bootstrapCacheLoader); Ehcache decoratedCache = decorateCache(rawCache); if (decoratedCache != rawCache) { this.cacheManager.replaceCacheWithDecoratedCache(rawCache, decoratedCache);
@Test public void testEhCacheFactoryBeanWithUpdatingSelfPopulatingCache() { EhCacheManagerFactoryBean cacheManagerFb = new EhCacheManagerFactoryBean(); cacheManagerFb.afterPropertiesSet(); try { CacheManager cm = cacheManagerFb.getObject(); EhCacheFactoryBean cacheFb = new EhCacheFactoryBean(); cacheFb.setCacheManager(cm); cacheFb.setCacheName("myCache1"); cacheFb.setCacheEntryFactory(new UpdatingCacheEntryFactory() { @Override public Object createEntry(Object key) { return key; } @Override public void updateEntryValue(Object key, Object value) { } }); assertEquals(cacheFb.getObjectType(), UpdatingSelfPopulatingCache.class); cacheFb.afterPropertiesSet(); Ehcache myCache1 = cm.getEhcache("myCache1"); assertTrue(myCache1 instanceof UpdatingSelfPopulatingCache); assertEquals("myKey1", myCache1.get("myKey1").getObjectValue()); } finally { cacheManagerFb.destroy(); } }
/** * Set the time to idle. * @see #setTimeToIdleSeconds(long) */ public void setTimeToIdle(int timeToIdle) { setTimeToIdleSeconds(timeToIdle); }
public EhCacheFactoryBean() { setMaxEntriesLocalHeap(10000); setMaxEntriesLocalDisk(10000000); setTimeToLiveSeconds(120); setTimeToIdleSeconds(120); }
/** * @see #setTimeToIdleSeconds(long) */ public void setTimeToIdle(int timeToIdle) { setTimeToIdleSeconds(timeToIdle); }
/** * Set the disk spool buffer size (in MB). * @see #setDiskSpoolBufferSizeMB(int) */ public void setDiskSpoolBufferSize(int diskSpoolBufferSize) { setDiskSpoolBufferSizeMB(diskSpoolBufferSize); }
/** * @see #setDiskSpoolBufferSizeMB(int) */ public void setDiskSpoolBufferSize(int diskSpoolBufferSize) { setDiskSpoolBufferSizeMB(diskSpoolBufferSize); }