Decides, at each call, which caches a cache annotation uses.
Normally the caches are fixed: the names in the annotation, looked up in
the CacheManager by a SimpleCacheResolver. A resolver of your own
can choose them from the call instead, for example one cache per
customer of a multi-tenant app, or always the same audit cache whatever
the annotation names (NamedCacheResolver). Declare it as a bean and
name it with cacheResolver: in the annotation or in @CacheConfig,
or make it the default with a CachingConfigurer.
// Caches per tenant: `books` becomes `acme.books`.
final class TenantCacheResolver implements CacheResolver {
TenantCacheResolver(this.manager, this.tenants);
final CacheManager manager;
final TenantContext tenants;
@override
Iterable<Cache> resolveCaches(
CacheOperationInvocationContext context,
) => [
for (final name in context.operation.cacheNames)
manager.getCache('${tenants.current}.$name')!,
];
}
@Cacheable('books', cacheResolver: 'tenantCacheResolver')
Book find(String isbn) => ...;
Spring (Java):
class TenantCacheResolver implements CacheResolver {
public Collection<? extends Cache> resolveCaches(
CacheOperationInvocationContext<?> context) { ... }
}
@Cacheable(cacheNames = "books", cacheResolver = "tenantCacheResolver")
Book find(String isbn) { ... }
- Implementers
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
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
resolveCaches(
CacheOperationInvocationContext context) → Iterable< Cache> -
The caches the operation of
contextreads or writes on this call. At least one is needed: an empty result fails the call with aStateError. -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited