Class EhCacheManagerUtils
- java.lang.Object
- org.springframework.cache.ehcache.EhCacheManagerUtils
public abstract class EhCacheManagerUtils extends Object
Convenient builder methods for EhCache 2.5+CacheManagersetup, providing easy programmatic bootstrapping from a Spring-provided resource. This is primarily intended for use within@Beanmethods in a Spring configuration class.These methods are a simple alternative to custom
CacheManagersetup code. For any advanced purposes, consider usingparseConfiguration(org.springframework.core.io.Resource), customizing the configuration object, and then calling theCacheManager(Configuration)constructor.- Since:
- 4.1
- Author:
- Juergen Hoeller
Constructor Summary
Constructors Constructor Description EhCacheManagerUtils()
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static CacheManagerbuildCacheManager()Build an EhCacheCacheManagerfrom the default configuration.static CacheManagerbuildCacheManager(String name)Build an EhCacheCacheManagerfrom the default configuration.static CacheManagerbuildCacheManager(String name, Resource configLocation)Build an EhCacheCacheManagerfrom the given configuration resource.static CacheManagerbuildCacheManager(Resource configLocation)Build an EhCacheCacheManagerfrom the given configuration resource.static ConfigurationparseConfiguration(Resource configLocation)Parse EhCache configuration from the given resource, for further use with customCacheManagercreation.
Constructor Detail
EhCacheManagerUtils
public EhCacheManagerUtils()
Method Detail
buildCacheManager
public static CacheManager buildCacheManager() throws CacheException
Build an EhCacheCacheManagerfrom the default configuration.The 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). If no configuration file can be found, a fail-safe fallback configuration will be used.
- Returns:
- the new EhCache CacheManager
- Throws:
CacheException- in case of configuration parsing failure
buildCacheManager
public static CacheManager buildCacheManager(String name) throws CacheException
Build an EhCacheCacheManagerfrom the default configuration.The 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). If no configuration file can be found, a fail-safe fallback configuration will be used.
- Parameters:
name- the desired name of the cache manager- Returns:
- the new EhCache CacheManager
- Throws:
CacheException- in case of configuration parsing failure
buildCacheManager
public static CacheManager buildCacheManager(Resource configLocation) throws CacheException
Build an EhCacheCacheManagerfrom the given configuration resource.- Parameters:
configLocation- the location of the configuration file (as a Spring resource)- Returns:
- the new EhCache CacheManager
- Throws:
CacheException- in case of configuration parsing failure
buildCacheManager
public static CacheManager buildCacheManager(String name, Resource configLocation) throws CacheException
Build an EhCacheCacheManagerfrom the given configuration resource.- Parameters:
name- the desired name of the cache managerconfigLocation- the location of the configuration file (as a Spring resource)- Returns:
- the new EhCache CacheManager
- Throws:
CacheException- in case of configuration parsing failure
parseConfiguration
public static Configuration parseConfiguration(Resource configLocation) throws CacheException
Parse EhCache configuration from the given resource, for further use with customCacheManagercreation.- Parameters:
configLocation- the location of the configuration file (as a Spring resource)- Returns:
- the EhCache Configuration handle
- Throws:
CacheException- in case of configuration parsing failure- See Also:
CacheManager(Configuration),CacheManager.create(Configuration)