CacheAnnotationMethodInterceptor class abstract

A composite ConditionalMethodInterceptor that transparently applies caching behavior based on JetLeaf cache annotations such as Cacheable, CachePut, and CacheEvict.

This interceptor is automatically invoked by the JetLeaf AOP subsystem whenever a method carries one or more cache annotations. It determines which type of cache operation(s) should run and orchestrates their lifecycle in a consistent order.

Interception Workflow

When a method is invoked:

  1. Before Invocation

    • If the method is annotated with @CacheEvict(beforeInvocation: true), the interceptor triggers the CacheEvictOperation before executing the actual method.
    • If the method is annotated with @Cacheable, the interceptor checks for existing cached data using CacheableOperation. If a cached value is found, it is returned immediately, bypassing method execution.
  2. Method Execution

    • If no cached result is found (a cache miss), the method proceeds normally and its result is captured.
  3. After Invocation

    • If the method is annotated with @CachePut, the result is stored in the cache through a CachePutOperation.
    • If the method is annotated with @Cacheable, and a cache miss occurred, the result is cached.
    • If the method is annotated with @CacheEvict(beforeInvocation: false), the CacheEvictOperation executes after method completion.

Ordering Guarantees

The interceptor ensures consistent execution order:

CacheEvict(beforeInvocation)
  → Cacheable
    → Method
      → CachePut
        → Cacheable (on miss)
          → CacheEvict(afterInvocation)

Example

final interceptor = MyCacheInterceptor();

final result = await interceptor.intercept(invocation);
// The interceptor will automatically handle caching semantics
// based on the annotations present on `invocation.method`.

See Also

Implementers

Properties

applicationContext ↔ ApplicationContext
The active JetLeaf ApplicationContext associated with this registrar.
getter/setter pair
cacheErrorHandler CacheErrorHandler
The configured error handler responsible for managing cache-related exceptions.
getter/setter pair
cacheResolver CacheResolver
The user-provided resolver responsible for locating caches by name.
getter/setter pair
hashCode int
The hash code for this object.
no setterinherited
keyGenerator KeyGenerator
The KeyGenerator responsible for producing unique and consistent cache keys for annotated method invocations.
getter/setter pair
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

afterInvocation<T>(MethodInvocation<T> invocation) FutureOr<void>
Invoked after the method execution completes, whether it succeeded or failed.
afterReturning<T>(MethodInvocation<T> invocation, Object? returnValue, Class? returnClass) FutureOr<void>
Invoked after a successful method execution.
aroundInvocation<T>(MethodInvocation<T> invocation) Future<T?>
Invoked around the target method execution, allowing interception both before and after invocation.
beforeInvocation<T>(MethodInvocation<T> invocation) FutureOr<void>
Executed immediately before the target method invocation.
canIntercept(Method method) bool
Determines whether this interceptor can intercept the specified method.
equalizedProperties() List<Object?>
Mixin-style contract for value-based equality, hashCode, and toString.
inherited
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