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

EhCacheManagerFactoryBean

open class EhCacheManagerFactoryBean : FactoryBean<CacheManager>, InitializingBean, DisposableBean

FactoryBean that exposes an EhCache net.sf.ehcache.CacheManager instance (independent or shared), configured from a specified config location.

If no config location is specified, a CacheManager will be configured from "ehcache.xml" in the root of the class path (that is, default EhCache initialization - as defined in the EhCache docs - will apply).

Setting up a separate EhCacheManagerFactoryBean is also advisable when using EhCacheFactoryBean, as it provides a (by default) independent CacheManager instance and cares for proper shutdown of the CacheManager. EhCacheManagerFactoryBean is also necessary for loading EhCache configuration from a non-default config location.

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
#setConfigLocation#setSharedEhCacheFactoryBeannet.sf.ehcache.CacheManager

Constructors

<init>

EhCacheManagerFactoryBean()

FactoryBean that exposes an EhCache net.sf.ehcache.CacheManager instance (independent or shared), configured from a specified config location.

If no config location is specified, a CacheManager will be configured from "ehcache.xml" in the root of the class path (that is, default EhCache initialization - as defined in the EhCache docs - will apply).

Setting up a separate EhCacheManagerFactoryBean is also advisable when using EhCacheFactoryBean, as it provides a (by default) independent CacheManager instance and cares for proper shutdown of the CacheManager. EhCacheManagerFactoryBean is also necessary for loading EhCache configuration from a non-default config location.

Note: As of Spring 5.0, Spring's EhCache support requires EhCache 2.10 or higher.

Functions

afterPropertiesSet

open fun afterPropertiesSet(): Unit

destroy

open fun destroy(): Unit

getObject

open fun getObject(): CacheManager

getObjectType

open fun getObjectType(): Class<out CacheManager>

isSingleton

open fun isSingleton(): Boolean

setAcceptExisting

open fun setAcceptExisting(acceptExisting: Boolean): Unit

Set whether an existing EhCache CacheManager of the same name will be accepted for this EhCacheManagerFactoryBean setup. Default is "false".

Typically used in combination with "cacheManagerName" but will simply work with the default CacheManager name if none specified. All references to the same CacheManager name (or the same default) in the same ClassLoader space will share the specified CacheManager then.

setCacheManagerName

open fun setCacheManagerName(cacheManagerName: String): Unit

Set the name of the EhCache CacheManager (if a specific name is desired).

setConfigLocation

open fun setConfigLocation(configLocation: Resource): Unit

Set the location of the EhCache config file. A typical value is "/WEB-INF/ehcache.xml".

Default is "ehcache.xml" in the root of the class path, or if not found, "ehcache-failsafe.xml" in the EhCache jar (default EhCache initialization).

setShared

open fun setShared(shared: Boolean): Unit

Set whether the EhCache CacheManager should be shared (as a singleton at the ClassLoader level) or independent (typically local within the application). Default is "false", creating an independent local instance.

NOTE: This feature allows for sharing this EhCacheManagerFactoryBean's CacheManager with any code calling CacheManager.create() in the same ClassLoader space, with no need to agree on a specific CacheManager name. However, it only supports a single EhCacheManagerFactoryBean involved which will control the lifecycle of the underlying CacheManager (in particular, its shutdown).

This flag overrides "acceptExisting" if both are set, since it indicates the 'stronger' mode of sharing.