Package io.micronaut.cache.interceptor
Class CacheInterceptor
- java.lang.Object
-
- io.micronaut.cache.interceptor.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 annotationsCacheable
,CachePut
andCacheInvalidate
.- Since:
- 1.0
-
-
Field Summary
Fields Modifier and Type Field Description static int
POSITION
The position on the interceptor in the chain.
-
Constructor Summary
Constructors Constructor Description CacheInterceptor(CacheManager cacheManager, CacheErrorHandler errorHandler, AsyncCacheErrorHandler asyncCacheErrorHandler, java.util.concurrent.ExecutorService ioExecutor, io.micronaut.context.BeanContext beanContext)
Create Cache Interceptor with given arguments.
-
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.
-
-
-
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 managererrorHandler
- Cache error handlerasyncCacheErrorHandler
- Async cache error handlersioExecutor
- The executor to create tasksbeanContext
- The bean context to allow DI
-
-
Method Detail
-
getOrder
public int getOrder()
- Specified by:
getOrder
in interfaceio.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 interfaceio.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 invocationreturnType
- 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 invocationintercept
- The intercepted resultreturnTypeObject
- The return type of the method in MicronautrequiredType
- 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
-
-