CacheResolver class abstract interface

Strategy interface for resolving one or more CacheStorage instances associated with a particular Cacheable operation.

A CacheResolver is responsible for determining which caches should participate in a given cache operation (e.g., @Cacheable, @CachePut, @CacheEvict). Implementations can apply a wide range of strategies — from simple name-based lookups to dynamic, context-aware cache routing.

Overview

The CacheResolver abstraction allows the JetLeaf caching framework to remain decoupled from the underlying cache resolution logic. Instead of binding directly to a single CacheManager, JetLeaf can delegate the resolution process to one or more resolvers that determine appropriate cache instances based on annotations, environment, or runtime conditions.

Typical Implementations

  • DefaultCacheResolver — resolves caches by name from a registered CacheManager.
  • TenantCacheResolver — routes caches dynamically per tenant.
  • CompositeCacheResolver — aggregates multiple resolvers using a chain-of-responsibility model (see _CacheResolverChain).
  • DynamicExpressionResolver — evaluates expressions or conditions to determine target caches at runtime.

Example

class CustomCacheResolver implements CacheResolver {
  final CacheManager manager;

  CustomCacheResolver(this.manager);

  @override
  FutureOr<Iterable<Cache>> resolveCaches(Cacheable cacheable) async {
    final caches = <Cache>[];
    for (final name in cacheable.cacheNames) {
      final cache = await manager.getCache('${AppEnv.prefix}::$name');
      if (cache != null) caches.add(cache);
    }
    return caches;
  }
}

Resolution Behavior

  • Implementations must never return null; return an empty collection if no caches are resolved.
  • Implementations may cache resolved instances for performance, but must handle invalidation appropriately if the cache topology changes.
  • The framework may invoke resolveCaches() multiple times for different cache operations, so resolution should be efficient and idempotent.

Thread Safety

Implementations must be thread-safe if used in multi-isolate or concurrent environments.

Error Handling

  • Throwing an exception will typically abort the resolution process.
  • When used in composite structures like _CacheResolverChain, individual resolver errors are ignored to preserve fault tolerance.

See Also

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(Cacheable cacheable, MethodInvocation invocation) FutureOr<Iterable<CacheStorage>>
Resolves the CacheStorage instances to be used for a given Cacheable operation.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited