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. Consider extendingCachingConfigurerSupport
, which provides a stub implementation of all interface methods.See @
EnableCaching
for general examples and context; seecacheManager()
,cacheResolver()
andkeyGenerator()
for detailed instructions.- Since:
- 3.1
- Author:
- Chris Beams, Stephane Nicoll
- See Also:
EnableCaching
,CachingConfigurerSupport
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description CacheManager
cacheManager()
Return the cache manager bean to use for annotation-driven cache management.CacheResolver
cacheResolver()
Return theCacheResolver
bean to use to resolve regular caches for annotation-driven cache management.CacheErrorHandler
errorHandler()
Return theCacheErrorHandler
to use to handle cache-related errors.KeyGenerator
keyGenerator()
Return the key generator bean to use for annotation-driven cache management.
Method Detail
cacheManager
@Nullable CacheManager cacheManager()
Return the cache manager bean to use for annotation-driven cache management. A defaultCacheResolver
will be initialized behind the scenes with this cache manager. For more fine-grained management of the cache resolution, consider setting theCacheResolver
directly.Implementations must explicitly declare
@Bean
, e.g.@Configuration @EnableCaching public class AppConfig extends CachingConfigurerSupport { @Bean // important! @Override public CacheManager cacheManager() { // configure and return CacheManager instance } // ... }
See @EnableCaching
for more complete examples.
cacheResolver
@Nullable CacheResolver cacheResolver()
Return theCacheResolver
bean to use to resolve regular caches for annotation-driven cache management. This is an alternative and more powerful option of specifying theCacheManager
to use.If both a
cacheManager()
and#cacheResolver()
are set, the cache manager is ignored.Implementations must explicitly declare
@Bean
, e.g.@Configuration @EnableCaching public class AppConfig extends CachingConfigurerSupport { @Bean // important! @Override public CacheResolver cacheResolver() { // configure and return CacheResolver instance } // ... }
SeeEnableCaching
for more complete examples.
keyGenerator
@Nullable KeyGenerator keyGenerator()
Return the key generator bean to use for annotation-driven cache management. Implementations must explicitly declare@Bean
, e.g.@Configuration @EnableCaching public class AppConfig extends CachingConfigurerSupport { @Bean // important! @Override public KeyGenerator keyGenerator() { // configure and return KeyGenerator instance } // ... }
See @EnableCaching
for more complete examples.
errorHandler
@Nullable CacheErrorHandler errorHandler()
Return theCacheErrorHandler
to use to handle cache-related errors.By default,
SimpleCacheErrorHandler
is used and simply throws the exception back at the client.Implementations must explicitly declare
@Bean
, e.g.@Configuration @EnableCaching public class AppConfig extends CachingConfigurerSupport { @Bean // important! @Override public CacheErrorHandler errorHandler() { // configure and return CacheErrorHandler instance } // ... }
See @EnableCaching
for more complete examples.