spring-framework / org.springframework.cache.ehcache / EhCacheFactoryBean

EhCacheFactoryBean

open class EhCacheFactoryBean : CacheConfiguration, FactoryBean<Ehcache>, BeanNameAware, InitializingBean

FactoryBean that creates a named EhCache net.sf.ehcache.Cache instance (or a decorator that implements the net.sf.ehcache.Ehcache interface), representing a cache region within an EhCache net.sf.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.

Author
Juergen Hoeller

Author
Dmitriy Kopylenko

Since
1.1.1

See Also
#setCacheManagerEhCacheManagerFactoryBeannet.sf.ehcache.Cache

Constructors

<init>

EhCacheFactoryBean()

Functions

afterPropertiesSet

open fun afterPropertiesSet(): Unit

getObject

open fun getObject(): Ehcache

getObjectType

open fun getObjectType(): Class<out Ehcache>

Predict the particular Ehcache implementation that will be returned from #getObject() based on logic in #createCache() and #decorateCache(Ehcache) as orchestrated by #afterPropertiesSet().

isSingleton

open fun isSingleton(): Boolean

setBeanName

open fun setBeanName(name: String): Unit

setBlocking

open fun setBlocking(blocking: Boolean): Unit

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.

setBootstrapCacheLoader

open fun setBootstrapCacheLoader(bootstrapCacheLoader: BootstrapCacheLoader): Unit

Set an EhCache net.sf.ehcache.bootstrap.BootstrapCacheLoader for this cache, if any.

setCacheEntryFactory

open fun setCacheEntryFactory(cacheEntryFactory: CacheEntryFactory): Unit

Set an EhCache net.sf.ehcache.constructs.blocking.CacheEntryFactory to use for a self-populating cache. If such a factory is specified, the cache will be decorated with EhCache's net.sf.ehcache.constructs.blocking.SelfPopulatingCache.

The specified factory can be of type net.sf.ehcache.constructs.blocking.UpdatingCacheEntryFactory, which will lead to the use of an net.sf.ehcache.constructs.blocking.UpdatingSelfPopulatingCache.

Note: Any such self-populating cache is automatically a blocking cache.

setCacheEventListeners

open fun setCacheEventListeners(cacheEventListeners: MutableSet<CacheEventListener>): Unit

Specify EhCache net.sf.ehcache.event.CacheEventListener to registered with this cache.

setCacheManager

open fun setCacheManager(cacheManager: CacheManager): Unit

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.

setCacheName

open fun setCacheName(cacheName: String): Unit

Set a name for which to retrieve or create a cache instance. Default is the bean name of this EhCacheFactoryBean.

setDisabled

open fun setDisabled(disabled: Boolean): Unit

Set whether this cache should be marked as disabled.

setDiskSpoolBufferSize

open fun setDiskSpoolBufferSize(diskSpoolBufferSize: Int): Unit

setTimeToIdle

open fun setTimeToIdle(timeToIdle: Int): Unit

setTimeToLive

open fun setTimeToLive(timeToLive: Int): Unit