Interface CachingConfigurer

All Known Subinterfaces:
JCacheConfigurer
All Known Implementing Classes:
CachingConfigurerSupport, JCacheConfigurerSupport

public interface CachingConfigurer
Interface to be implemented by @Configuration classes annotated with @EnableCaching that wish or need to specify explicitly how caches are resolved and how keys are generated for annotation-driven cache management.

See @EnableCaching for general examples and context; see cacheManager(), cacheResolver(), keyGenerator(), and errorHandler() for detailed instructions.

Since:
3.1
Author:
Chris Beams, Stephane Nicoll
See Also:
  • Method Details

    • cacheManager

      @Nullable default CacheManager cacheManager()
      Return the cache manager bean to use for annotation-driven cache management. A default CacheResolver will be initialized behind the scenes with this cache manager. For more fine-grained management of the cache resolution, consider setting the CacheResolver directly.

      Implementations must explicitly declare @Bean so that the cache manager participates in the lifecycle of the context, e.g.

       @Configuration
       @EnableCaching
       class AppConfig implements CachingConfigurer {
           @Bean // important!
           @Override
           CacheManager cacheManager() {
               // configure and return CacheManager instance
           }
           // ...
       }
       
      See @EnableCaching for more complete examples.
    • cacheResolver

      @Nullable default CacheResolver cacheResolver()
      Return the CacheResolver bean to use to resolve regular caches for annotation-driven cache management. This is an alternative and more powerful option of specifying the CacheManager to use.

      If both a cacheManager() and cacheResolver() are set, the cache manager is ignored.

      Implementations must explicitly declare @Bean so that the cache resolver participates in the lifecycle of the context, e.g.

       @Configuration
       @EnableCaching
       class AppConfig implements CachingConfigurer {
           @Bean // important!
           @Override
           CacheResolver cacheResolver() {
               // configure and return CacheResolver instance
           }
           // ...
       }
       
      See EnableCaching for more complete examples.
    • keyGenerator

      @Nullable default KeyGenerator keyGenerator()
      Return the key generator bean to use for annotation-driven cache management.

      By default, SimpleKeyGenerator is used. See @EnableCaching for more complete examples.

    • errorHandler

      @Nullable default CacheErrorHandler errorHandler()
      Return the CacheErrorHandler to use to handle cache-related errors.

      By default, SimpleCacheErrorHandler is used, which throws the exception back at the client. See @EnableCaching for more complete examples.