Class EhCacheFactoryBean
- java.lang.Object
-
- org.onebusaway.container.spring.ehcache.EhCacheFactoryBean
-
- All Implemented Interfaces:
org.springframework.beans.factory.Aware,org.springframework.beans.factory.BeanNameAware,org.springframework.beans.factory.FactoryBean<net.sf.ehcache.Ehcache>,org.springframework.beans.factory.InitializingBean
public class EhCacheFactoryBean extends Object implements org.springframework.beans.factory.FactoryBean<net.sf.ehcache.Ehcache>, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.InitializingBean
A SpringFactoryBeanfor programmatically creating an EhCacheCachewith standard configuration options, but also progrmattic Terracotta configuration. A special note about Terracotta config. While you can create all your Terracotta-enabled caches programatically using this FactoryBean, you need to have at least one Terracotta-enabled cache created the old fashioned way (through anehcache.xmlresource config) so that theCacheManagerwill properly enable Terracotta support.- Author:
- bdferris
-
-
Field Summary
Fields Modifier and Type Field Description protected org.apache.commons.logging.Loglogger
-
Constructor Summary
Constructors Constructor Description EhCacheFactoryBean()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidafterPropertiesSet()protected net.sf.ehcache.EhcachedecorateCache(net.sf.ehcache.Ehcache cache)Decorate the given Cache, if necessary.net.sf.ehcache.EhcachegetObject()Class<?>getObjectType()booleanisSingleton()voidsetBeanName(String name)voidsetBlocking(boolean blocking)Set whether to use a blocking cache that lets read attempts block until the requested element is created.voidsetCacheEntryFactory(net.sf.ehcache.constructs.blocking.CacheEntryFactory cacheEntryFactory)Set an EHCacheCacheEntryFactoryto use for a self-populating cache.voidsetCacheManager(net.sf.ehcache.CacheManager cacheManager)Set a CacheManager from which to retrieve a named Cache instance.voidsetCacheName(String cacheName)Set a name for which to retrieve or create a cache instance.voidsetDiskExpiryThreadIntervalSeconds(int diskExpiryThreadIntervalSeconds)Set the number of seconds between runs of the disk expiry thread.voidsetDiskPersistent(boolean diskPersistent)Set whether the disk store persists between restarts of the Virtual Machine.voidsetEternal(boolean eternal)Set whether elements are considered as eternal.voidsetMaxElementsInMemory(int maxElementsInMemory)Specify the maximum number of cached objects in memory.voidsetMaxElementsOnDisk(int maxElementsOnDisk)Specify the maximum number of cached objects on disk.voidsetMemoryStoreEvictionPolicy(net.sf.ehcache.store.MemoryStoreEvictionPolicy memoryStoreEvictionPolicy)Set the memory style eviction policy for this cache.voidsetOverflowToDisk(boolean overflowToDisk)Set whether elements can overflow to disk when the in-memory cache has reached the maximum size limit.voidsetTerracottaClustered(boolean terracottaClustered)voidsetTimeToIdle(int timeToIdle)Set the time in seconds to idle for an element before it expires, that is, the maximum amount of time between accesses before an element expires.voidsetTimeToLive(int timeToLive)Set t he time in seconds to live for an element before it expires, i.e. the maximum time between creation time and when an element expires.
-
-
-
Method Detail
-
setCacheManager
public void setCacheManager(net.sf.ehcache.CacheManager cacheManager)
Set a CacheManager from which to retrieve a named Cache instance. By default,CacheManager.getInstance()will be called.Note that in particular for persistent caches, it is advisable to properly handle the shutdown of the CacheManager: Set up a separate EhCacheManagerFactoryBean and pass a reference to this bean property.
A separate EhCacheManagerFactoryBean is also necessary for loading EHCache configuration from a non-default config location.
- See Also:
EhCacheManagerFactoryBean,CacheManager.getInstance()
-
setCacheName
public void setCacheName(String cacheName)
Set a name for which to retrieve or create a cache instance. Default is the bean name of this EhCacheFactoryBean.
-
setMaxElementsInMemory
public void setMaxElementsInMemory(int maxElementsInMemory)
Specify the maximum number of cached objects in memory. Default is 10000 elements.
-
setMaxElementsOnDisk
public void setMaxElementsOnDisk(int maxElementsOnDisk)
Specify the maximum number of cached objects on disk. Default is 10000000 elements.
-
setMemoryStoreEvictionPolicy
public void setMemoryStoreEvictionPolicy(net.sf.ehcache.store.MemoryStoreEvictionPolicy memoryStoreEvictionPolicy)
Set the memory style eviction policy for this cache. Supported values are "LRU", "LFU" and "FIFO", according to the constants defined in EHCache's MemoryStoreEvictionPolicy class. Default is "LRU".
-
setOverflowToDisk
public void setOverflowToDisk(boolean overflowToDisk)
Set whether elements can overflow to disk when the in-memory cache has reached the maximum size limit. Default is "true".
-
setEternal
public void setEternal(boolean eternal)
Set whether elements are considered as eternal. If "true", timeouts are ignored and the element is never expired. Default is "false".
-
setTimeToLive
public void setTimeToLive(int timeToLive)
Set t he time in seconds to live for an element before it expires, i.e. the maximum time between creation time and when an element expires. It is only used if the element is not eternal. Default is 300 seconds.
-
setTimeToIdle
public void setTimeToIdle(int timeToIdle)
Set the time in seconds to idle for an element before it expires, that is, the maximum amount of time between accesses before an element expires. This is only used if the element is not eternal. Default is 120 seconds.
-
setDiskPersistent
public void setDiskPersistent(boolean diskPersistent)
Set whether the disk store persists between restarts of the Virtual Machine. The default is "false".
-
setDiskExpiryThreadIntervalSeconds
public void setDiskExpiryThreadIntervalSeconds(int diskExpiryThreadIntervalSeconds)
Set the number of seconds between runs of the disk expiry thread. The default is 300 seconds.
-
setBlocking
public void setBlocking(boolean blocking)
Set whether to use a blocking cache that lets read attempts block until the requested element is created.If you intend to build a self-populating blocking cache, consider specifying a
CacheEntryFactory.- See Also:
BlockingCache,setCacheEntryFactory(net.sf.ehcache.constructs.blocking.CacheEntryFactory)
-
setTerracottaClustered
public void setTerracottaClustered(boolean terracottaClustered)
-
setCacheEntryFactory
public void setCacheEntryFactory(net.sf.ehcache.constructs.blocking.CacheEntryFactory cacheEntryFactory)
Set an EHCacheCacheEntryFactoryto use for a self-populating cache. If such a factory is specified, the cache will be decorated with EHCache'sSelfPopulatingCache.The specified factory can be of type
UpdatingCacheEntryFactory, which will lead to the use of anUpdatingSelfPopulatingCache.Note: Any such self-populating cache is automatically a blocking cache.
- See Also:
SelfPopulatingCache,UpdatingSelfPopulatingCache,UpdatingCacheEntryFactory
-
setBeanName
public void setBeanName(String name)
- Specified by:
setBeanNamein interfaceorg.springframework.beans.factory.BeanNameAware
-
afterPropertiesSet
public void afterPropertiesSet() throws net.sf.ehcache.CacheException, IOException- Specified by:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean- Throws:
net.sf.ehcache.CacheExceptionIOException
-
decorateCache
protected net.sf.ehcache.Ehcache decorateCache(net.sf.ehcache.Ehcache cache)
Decorate the given Cache, if necessary.- Parameters:
cache- the raw Cache object, based on the configuration of this FactoryBean- Returns:
- the (potentially decorated) cache object to be registered with the CacheManager
-
getObject
public net.sf.ehcache.Ehcache getObject()
- Specified by:
getObjectin interfaceorg.springframework.beans.factory.FactoryBean<net.sf.ehcache.Ehcache>
-
getObjectType
public Class<?> getObjectType()
- Specified by:
getObjectTypein interfaceorg.springframework.beans.factory.FactoryBean<net.sf.ehcache.Ehcache>
-
isSingleton
public boolean isSingleton()
- Specified by:
isSingletonin interfaceorg.springframework.beans.factory.FactoryBean<net.sf.ehcache.Ehcache>
-
-