Class EhCacheManagerUtils
- java.lang.Object
- org.springframework.cache.ehcache.EhCacheManagerUtils
public abstract class EhCacheManagerUtils extends Object
Convenient builder methods for EhCache 2.5+CacheManager
setup, providing easy programmatic bootstrapping from a Spring-provided resource. This is primarily intended for use within@Bean
methods in a Spring configuration class.These methods are a simple alternative to custom
CacheManager
setup 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 CacheManager
buildCacheManager()
Build an EhCacheCacheManager
from the default configuration.static CacheManager
buildCacheManager(String name)
Build an EhCacheCacheManager
from the default configuration.static CacheManager
buildCacheManager(String name, Resource configLocation)
Build an EhCacheCacheManager
from the given configuration resource.static CacheManager
buildCacheManager(Resource configLocation)
Build an EhCacheCacheManager
from the given configuration resource.static Configuration
parseConfiguration(Resource configLocation)
Parse EhCache configuration from the given resource, for further use with customCacheManager
creation.
Constructor Detail
EhCacheManagerUtils
public EhCacheManagerUtils()
Method Detail
buildCacheManager
public static CacheManager buildCacheManager() throws CacheException
Build an EhCacheCacheManager
from 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 EhCacheCacheManager
from 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 EhCacheCacheManager
from 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 EhCacheCacheManager
from 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 customCacheManager
creation.- 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)