org.springframework.cache.ehcache

Class EhCacheManagerUtils

  • java.lang.Object
    • org.springframework.cache.ehcache.EhCacheManagerUtils


  • public abstract class EhCacheManagerUtils
    extends java.lang.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 using parseConfiguration(org.springframework.core.io.Resource), customizing the configuration object, and then calling the CacheManager.CacheManager(Configuration) constructor.

    Since:
    4.1
    Author:
    Juergen Hoeller
    • Constructor Detail

      • EhCacheManagerUtils

        public EhCacheManagerUtils()
    • Method Detail

      • buildCacheManager

        public static CacheManager buildCacheManager()
                                              throws CacheException
        Build an EhCache CacheManager 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(java.lang.String name)
                                              throws CacheException
        Build an EhCache CacheManager 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 EhCache CacheManager 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(java.lang.String name,
                                                     Resource configLocation)
                                              throws CacheException
        Build an EhCache CacheManager from the given configuration resource.
        Parameters:
        name - the desired name of the cache manager
        configLocation - the location of the configuration file (as a Spring resource)
        Returns:
        the new EhCache CacheManager
        Throws:
        CacheException - in case of configuration parsing failure