Sets, in one place, what every cache annotation uses unless it says otherwise: the cache manager, the cache resolver, the key generator and the handler for errors thrown by caches.
Most applications do not need it: the starter's defaults suit them, and
a single annotation can already name its own keyGenerator,
cacheManager or cacheResolver. Use it to change a default for the
whole application, typically the error handler, so that a cache that is
down only means "no cache". Declare one bean of it (usually a
@Configuration class that mixes it in) and override the methods to
change. A method returning null keeps the default:
| Method | Default |
|---|---|
| cacheManager | the CacheManager bean |
| cacheResolver | a SimpleCacheResolver of the cache manager |
| keyGenerator | SimpleKeyGenerator |
| errorHandler | SimpleCacheErrorHandler (rethrows) |
The methods are called once, when the first cache operation needs them.
Return objects (or beans injected into the configuration) rather than
marking the methods @Bean: @Configuration classes are not proxied in
Dart, so calling a @Bean method creates a second instance.
// Normalized isbn keys everywhere, and a broken cache only logs.
@Configuration()
class CacheSetup with CachingConfigurer {
@override
KeyGenerator keyGenerator() => const IsbnKeys();
@override
CacheErrorHandler errorHandler() => const LoggingCacheErrorHandler();
}
Spring (Java):
@Configuration
@EnableCaching
class CacheSetup implements CachingConfigurer {
@Override
public KeyGenerator keyGenerator() { return new IsbnKeys(); }
@Override
public CacheErrorHandler errorHandler() {
return new LoggingCacheErrorHandler();
}
}
Constructors
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
cacheManager(
) → CacheManager? -
The cache manager of operations that name none;
null(the default) for theCacheManagerbean. Not used when cacheResolver returns a resolver. -
cacheResolver(
) → CacheResolver? -
The cache resolver of operations that name neither a cache manager
nor a resolver;
null(the default) for aSimpleCacheResolverof the cache manager. -
errorHandler(
) → CacheErrorHandler? -
What happens when a cache throws;
null(the default) forSimpleCacheErrorHandler, which lets the error reach the caller of the cached method. -
keyGenerator(
) → KeyGenerator? -
The key generator of operations that set neither
keynorkeyGenerator;null(the default) forSimpleKeyGenerator, which makes the key from the arguments. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited