Class CacheInterceptor

  • All Implemented Interfaces:
    io.micronaut.aop.Interceptor<java.lang.Object,​java.lang.Object>, io.micronaut.aop.MethodInterceptor<java.lang.Object,​java.lang.Object>, io.micronaut.core.order.Ordered

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

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

    Since:
    1.0
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int POSITION
      The position on the interceptor in the chain.
      • Fields inherited from interface io.micronaut.aop.Interceptor

        ARGUMENT, CACHEABLE_LAZY_TARGET, HOTSWAP, LAZY, PROXY_TARGET
      • Fields inherited from interface io.micronaut.core.order.Ordered

        HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected java.lang.Object doContextProceed​(io.micronaut.aop.MethodInvocationContext context)  
      int getOrder()  
      java.lang.Object intercept​(io.micronaut.aop.MethodInvocationContext<java.lang.Object,​java.lang.Object> context)  
      protected java.util.concurrent.CompletionStage<?> interceptAsCompletableFuture​(io.micronaut.aop.MethodInvocationContext<java.lang.Object,​java.lang.Object> context, java.util.function.Supplier<java.util.concurrent.CompletionStage<?>> intercept, io.micronaut.core.type.ReturnType<?> returnTypeObject, io.micronaut.core.type.Argument<?> requiredType)
      Intercept the async method invocation.
      protected java.lang.Object interceptSync​(io.micronaut.aop.MethodInvocationContext context, io.micronaut.core.type.ReturnType<?> returnType)
      Intercept the annotated method invocation with sync.
      protected java.util.List<io.micronaut.core.annotation.AnnotationValue<CacheInvalidate>> invalidateOperations​(io.micronaut.inject.ExecutableMethod<?,​?> method)
      Evict from the cache.
      protected java.util.List<io.micronaut.core.annotation.AnnotationValue<CachePut>> putOperations​(io.micronaut.inject.ExecutableMethod<?,​?> method)
      Saving inside the cache.
      protected CacheKeyGenerator resolveKeyGenerator​(java.lang.Class<? extends CacheKeyGenerator> type)
      Resolve the cache key generator from the give type.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface io.micronaut.aop.MethodInterceptor

        intercept
    • Field Detail

      • POSITION

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

      • CacheInterceptor

        public CacheInterceptor​(CacheManager cacheManager,
                                CacheErrorHandler errorHandler,
                                AsyncCacheErrorHandler asyncCacheErrorHandler,
                                @Named("io")
                                java.util.concurrent.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 Detail

      • getOrder

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

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

        protected java.lang.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 java.util.concurrent.CompletionStage<?> interceptAsCompletableFuture​(io.micronaut.aop.MethodInvocationContext<java.lang.Object,​java.lang.Object> context,
                                                                                       java.util.function.Supplier<java.util.concurrent.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 java.util.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 java.util.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​(java.lang.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 java.lang.Object doContextProceed​(io.micronaut.aop.MethodInvocationContext context)
        Parameters:
        context - the method invocation context
        Returns:
        the proceed result