Class CacheInterceptor

java.lang.Object
io.micronaut.cache.interceptor.CacheInterceptor
All Implemented Interfaces:
io.micronaut.aop.Interceptor<Object,Object>, io.micronaut.aop.MethodInterceptor<Object,Object>, io.micronaut.core.order.Ordered

@InterceptorBean(CacheAnnotation.class) public class CacheInterceptor extends Object implements io.micronaut.aop.MethodInterceptor<Object,Object>

An AOP MethodInterceptor implementation for the Cache annotations Cacheable, CachePut and CacheInvalidate.

Since:
1.0
Author:
Graeme Rocher
  • Field Details

    • POSITION

      public static final int POSITION
      The position on the interceptor in the chain.
  • Constructor Details

    • CacheInterceptor

      public CacheInterceptor(CacheManager cacheManager, CacheErrorHandler errorHandler, AsyncCacheErrorHandler asyncCacheErrorHandler, @Named("io") ExecutorService ioExecutor, io.micronaut.context.BeanContext beanContext)
      Create Cache Interceptor with given arguments.
      Parameters:
      cacheManager - The cache manager
      errorHandler - Cache error handler
      asyncCacheErrorHandler - Async cache error handlers
      ioExecutor - The executor to create tasks
      beanContext - The bean context to allow DI
  • Method Details

    • getOrder

      public int getOrder()
      Specified by:
      getOrder in interface io.micronaut.core.order.Ordered
    • intercept

      public Object intercept(io.micronaut.aop.MethodInvocationContext<Object,Object> context)
      Specified by:
      intercept in interface io.micronaut.aop.MethodInterceptor<Object,Object>
    • interceptSync

      protected Object interceptSync(io.micronaut.aop.MethodInvocationContext context, io.micronaut.core.type.ReturnType<?> returnType)
      Intercept the annotated method invocation with sync.
      Parameters:
      context - Contains information about method invocation
      returnType - The return type class
      Returns:
      The value from the cache
    • interceptAsCompletableFuture

      protected CompletionStage<?> interceptAsCompletableFuture(io.micronaut.aop.MethodInvocationContext<Object,Object> context, Supplier<CompletionStage<?>> intercept, io.micronaut.core.type.ReturnType<?> returnTypeObject, io.micronaut.core.type.Argument<?> requiredType)
      Intercept the async method invocation.
      Parameters:
      context - Contains information about method invocation
      intercept - The intercepted result
      returnTypeObject - The return type of the method in Micronaut
      requiredType - The return type class
      Returns:
      The value from the cache
    • putOperations

      protected List<io.micronaut.core.annotation.AnnotationValue<CachePut>> putOperations(io.micronaut.inject.ExecutableMethod<?,?> method)
      Saving inside the cache.
      Parameters:
      method - Contains information about method invocation
      Returns:
      The operations to cause the return value to be cached within the given cache name.
    • invalidateOperations

      protected List<io.micronaut.core.annotation.AnnotationValue<CacheInvalidate>> invalidateOperations(io.micronaut.inject.ExecutableMethod<?,?> method)
      Evict from the cache.
      Parameters:
      method - Contains information about method invocation
      Returns:
      The operations to cause the eviction of the given caches
    • resolveKeyGenerator

      protected CacheKeyGenerator resolveKeyGenerator(Class<? extends CacheKeyGenerator> type)
      Resolve the cache key generator from the give type.
      Parameters:
      type - The key generator
      Returns:
      The cache key generator
    • doContextProceed

      protected Object doContextProceed(io.micronaut.aop.MethodInvocationContext context)
      Parameters:
      context - the method invocation context
      Returns:
      the proceed result