public class EhCacheFactoryBean extends CacheConfiguration implements org.springframework.beans.factory.FactoryBean<Ehcache>, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.InitializingBean
FactoryBean
that creates a named EhCache Cache
instance
(or a decorator that implements the Ehcache
interface),
representing a cache region within an EhCache CacheManager
.
If the specified named cache is not configured in the cache configuration descriptor, this FactoryBean will construct an instance of a Cache with the provided name and the specified cache properties and add it to the CacheManager for later retrieval. If some or all properties are not set at configuration time, this FactoryBean will use defaults.
Note: If the named Cache instance is found, the properties will be ignored and the Cache instance will be retrieved from the CacheManager.
Note: As of Spring 5.0, Spring's EhCache support requires EhCache 2.10 or higher.
setCacheManager(net.sf.ehcache.CacheManager)
,
EhCacheManagerFactoryBean
,
Cache
CacheConfiguration.BootstrapCacheLoaderFactoryConfiguration, CacheConfiguration.CacheDecoratorFactoryConfiguration, CacheConfiguration.CacheEventListenerFactoryConfiguration, CacheConfiguration.CacheExceptionHandlerFactoryConfiguration, CacheConfiguration.CacheExtensionFactoryConfiguration, CacheConfiguration.CacheLoaderFactoryConfiguration, CacheConfiguration.TransactionalMode
Modifier and Type | Field and Description |
---|---|
protected Log |
logger |
bootstrapCacheLoaderFactoryConfiguration, cacheDecoratorConfigurations, cacheEventListenerConfigurations, cacheExceptionHandlerFactoryConfiguration, cacheExtensionConfigurations, cacheLoaderConfigurations, cacheLoaderTimeoutMillis, cacheWriterConfiguration, clearOnFlush, DEFAULT_CACHE_WRITER_CONFIGURATION, DEFAULT_CLEAR_ON_FLUSH, DEFAULT_COPY_ON_READ, DEFAULT_COPY_ON_WRITE, DEFAULT_COPY_STRATEGY_CONFIGURATION, DEFAULT_DISK_ACCESS_STRIPES, DEFAULT_DISK_PERSISTENT, DEFAULT_ETERNAL_VALUE, DEFAULT_EXPIRY_THREAD_INTERVAL_SECONDS, DEFAULT_LOGGING, DEFAULT_MAX_BYTES_OFF_HEAP, DEFAULT_MAX_BYTES_ON_DISK, DEFAULT_MAX_BYTES_ON_HEAP, DEFAULT_MAX_ELEMENTS_ON_DISK, DEFAULT_MAX_ENTRIES_IN_CACHE, DEFAULT_MEMORY_STORE_EVICTION_POLICY, DEFAULT_SPOOL_BUFFER_SIZE, DEFAULT_STATISTICS, DEFAULT_TRANSACTIONAL_MODE, DEFAULT_TTI, DEFAULT_TTL, diskAccessStripes, diskExpiryThreadIntervalSeconds, diskPersistent, diskSpoolBufferSizeMB, eternal, listeners, logging, maxElementsOnDisk, maxEntriesInCache, maxEntriesLocalHeap, memoryStoreEvictionPolicy, name, overflowToDisk, overflowToOffHeap, pinningConfiguration, terracottaConfiguration, timeToIdleSeconds, timeToLiveSeconds
Constructor and Description |
---|
EhCacheFactoryBean() |
Modifier and Type | Method and Description |
---|---|
void |
afterPropertiesSet() |
protected Cache |
createCache()
Create a raw Cache object based on the configuration of this FactoryBean.
|
protected Ehcache |
decorateCache(Ehcache cache)
Decorate the given Cache, if necessary.
|
Ehcache |
getObject() |
java.lang.Class<? extends Ehcache> |
getObjectType()
Predict the particular
Ehcache implementation that will be returned from
getObject() based on logic in createCache() and
decorateCache(Ehcache) as orchestrated by afterPropertiesSet() . |
boolean |
isSingleton() |
void |
setBeanName(java.lang.String name) |
void |
setBlocking(boolean blocking)
Set whether to use a blocking cache that lets read attempts block
until the requested element is created.
|
void |
setBootstrapCacheLoader(BootstrapCacheLoader bootstrapCacheLoader)
Set an EhCache
BootstrapCacheLoader
for this cache, if any. |
void |
setCacheEntryFactory(CacheEntryFactory cacheEntryFactory)
Set an EhCache
CacheEntryFactory
to use for a self-populating cache. |
void |
setCacheEventListeners(java.util.Set<CacheEventListener> cacheEventListeners)
Specify EhCache
cache event listeners
to registered with this cache. |
void |
setCacheManager(CacheManager cacheManager)
Set a CacheManager from which to retrieve a named Cache instance.
|
void |
setCacheName(java.lang.String cacheName)
Set a name for which to retrieve or create a cache instance.
|
void |
setDisabled(boolean disabled)
Set whether this cache should be marked as disabled.
|
void |
setDiskSpoolBufferSize(int diskSpoolBufferSize) |
void |
setTimeToIdle(int timeToIdle) |
void |
setTimeToLive(int timeToLive) |
addBootstrapCacheLoaderFactory, addCacheDecoratorFactory, addCacheEventListenerFactory, addCacheExceptionHandlerFactory, addCacheExtensionFactory, addCacheLoaderFactory, addCacheWriter, addConfigurationListener, addCopyStrategy, addDynamicSearchListener, addElementValueComparator, addPersistence, addPinning, addSearchable, addSizeOfPolicy, addTerracotta, bootstrapCacheLoaderFactory, cacheEventListenerFactory, cacheExceptionHandlerFactory, cacheExtensionFactory, cacheLoaderFactory, cacheWriter, clearOnFlush, clone, copyOnRead, copyOnWrite, diskAccessStripes, diskExpiryThreadIntervalSeconds, diskPersistent, diskSpoolBufferSizeMB, dynamicAttributeExtractor, eternal, freezeConfiguration, getBootstrapCacheLoaderFactoryConfiguration, getCacheDecoratorConfigurations, getCacheEventListenerConfigurations, getCacheExceptionHandlerFactoryConfiguration, getCacheExtensionConfigurations, getCacheLoaderConfigurations, getCacheLoaderTimeoutMillis, getCacheWriterConfiguration, getClassLoader, getCopyStrategy, getCopyStrategyConfiguration, getDiskAccessStripes, getDiskExpiryThreadIntervalSeconds, getDiskSpoolBufferSizeMB, getDynamicExtractor, getElementValueComparatorConfiguration, getLogging, getMaxBytesLocalDisk, getMaxBytesLocalDiskAsString, getMaxBytesLocalDiskPercentage, getMaxBytesLocalHeap, getMaxBytesLocalHeapAsString, getMaxBytesLocalHeapPercentage, getMaxBytesLocalOffHeap, getMaxBytesLocalOffHeapAsString, getMaxBytesLocalOffHeapPercentage, getMaxElementsInMemory, getMaxElementsOnDisk, getMaxEntriesInCache, getMaxEntriesLocalDisk, getMaxEntriesLocalHeap, getMaxMemoryOffHeap, getMaxMemoryOffHeapInBytes, getMemoryStoreEvictionPolicy, getName, getPersistenceConfiguration, getPinningConfiguration, getSearchable, getSearchAttributes, getSizeOfPolicyConfiguration, getStatistics, getTerracottaConfiguration, getTerracottaConsistency, getTimeToIdleSeconds, getTimeToLiveSeconds, getTransactionalMode, internalSetDiskCapacity, internalSetEternal, internalSetLogging, internalSetMaxBytesLocalOffheap, internalSetMaxEntriesInCache, internalSetMemCapacity, internalSetMemCapacityInBytes, internalSetOverflowToOffheap, internalSetTimeToIdle, internalSetTimeToLive, isClearOnFlush, isCopyOnRead, isCopyOnWrite, isCountBasedTuned, isDiskPersistent, isEternal, isFrozen, isLocalTransactional, isMaxBytesLocalDiskPercentageSet, isMaxBytesLocalHeapPercentageSet, isMaxBytesLocalOffHeapPercentageSet, isOverflowToDisk, isOverflowToOffHeap, isOverflowToOffHeapSet, isSearchable, isTerracottaClustered, isXaStrictTransactional, isXaTransactional, logging, maxBytesLocalDisk, maxBytesLocalHeap, maxBytesLocalOffHeap, maxElementsInMemory, maxElementsOnDisk, maxEntriesInCache, maxEntriesLocalDisk, maxEntriesLocalHeap, maxMemoryOffHeap, memoryStoreEvictionPolicy, memoryStoreEvictionPolicy, name, overflowToDisk, overflowToOffHeap, persistence, pinning, removeConfigurationListener, searchable, setCacheLoaderTimeoutMillis, setClassLoader, setClearOnFlush, setCopyOnRead, setCopyOnWrite, setDiskAccessStripes, setDiskExpiryThreadIntervalSeconds, setDiskPersistent, setDiskSpoolBufferSizeMB, setDynamicAttributesExtractor, setEternal, setLogging, setMaxBytesLocalDisk, setMaxBytesLocalDisk, setMaxBytesLocalHeap, setMaxBytesLocalHeap, setMaxBytesLocalOffHeap, setMaxBytesLocalOffHeap, setMaxElementsInMemory, setMaxElementsOnDisk, setMaxEntriesInCache, setMaxEntriesLocalDisk, setMaxEntriesLocalHeap, setMaxMemoryOffHeap, setMemoryStoreEvictionPolicy, setMemoryStoreEvictionPolicyFromObject, setName, setOverflowToDisk, setOverflowToOffHeap, setStatistics, setTimeToIdleSeconds, setTimeToLiveSeconds, setTransactionalMode, setupFor, setupFor, sizeOfPolicy, statistics, terracotta, timeoutMillis, timeToIdleSeconds, timeToLiveSeconds, transactionalMode, transactionalMode, validate, validateCompleteConfiguration, validateConfiguration
protected final Log logger
public void setCacheManager(CacheManager cacheManager)
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.
public void setCacheName(java.lang.String cacheName)
public void setTimeToLive(int timeToLive)
public void setTimeToIdle(int timeToIdle)
public void setDiskSpoolBufferSize(int diskSpoolBufferSize)
public void setBlocking(boolean blocking)
If you intend to build a self-populating blocking cache,
consider specifying a CacheEntryFactory
.
public void setCacheEntryFactory(CacheEntryFactory cacheEntryFactory)
CacheEntryFactory
to use for a self-populating cache. If such a factory is specified,
the cache will be decorated with EhCache's
SelfPopulatingCache
.
The specified factory can be of type
UpdatingCacheEntryFactory
,
which will lead to the use of an
UpdatingSelfPopulatingCache
.
Note: Any such self-populating cache is automatically a blocking cache.
public void setBootstrapCacheLoader(BootstrapCacheLoader bootstrapCacheLoader)
BootstrapCacheLoader
for this cache, if any.public void setCacheEventListeners(java.util.Set<CacheEventListener> cacheEventListeners)
cache event listeners
to registered with this cache.public void setDisabled(boolean disabled)
Cache.setDisabled(boolean)
public void setBeanName(java.lang.String name)
setBeanName
in interface org.springframework.beans.factory.BeanNameAware
public void afterPropertiesSet() throws CacheException
afterPropertiesSet
in interface org.springframework.beans.factory.InitializingBean
CacheException
protected Cache createCache()
protected Ehcache decorateCache(Ehcache cache)
cache
- the raw Cache object, based on the configuration of this FactoryBean@Nullable public Ehcache getObject()
getObject
in interface org.springframework.beans.factory.FactoryBean<Ehcache>
public java.lang.Class<? extends Ehcache> getObjectType()
Ehcache
implementation that will be returned from
getObject()
based on logic in createCache()
and
decorateCache(Ehcache)
as orchestrated by afterPropertiesSet()
.getObjectType
in interface org.springframework.beans.factory.FactoryBean<Ehcache>
public boolean isSingleton()
isSingleton
in interface org.springframework.beans.factory.FactoryBean<Ehcache>