Package io.micronaut.cache.interceptor
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 Summary
Modifier and TypeFieldDescriptionstatic final int
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
-
Constructor Summary
ConstructorDescriptionCacheInterceptor
(CacheManager cacheManager, CacheErrorHandler errorHandler, AsyncCacheErrorHandler asyncCacheErrorHandler, ExecutorService ioExecutor, io.micronaut.context.BeanContext beanContext) Create Cache Interceptor with given arguments. -
Method Summary
Modifier and TypeMethodDescriptionprotected Object
doContextProceed
(io.micronaut.aop.MethodInvocationContext context) int
getOrder()
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.protected Object
interceptSync
(io.micronaut.aop.MethodInvocationContext context, io.micronaut.core.type.ReturnType<?> returnType) Intercept the annotated method invocation with sync.protected List<io.micronaut.core.annotation.AnnotationValue<CacheInvalidate>>
invalidateOperations
(io.micronaut.inject.ExecutableMethod<?, ?> method) Evict from the cache.putOperations
(io.micronaut.inject.ExecutableMethod<?, ?> method) Saving inside the cache.protected CacheKeyGenerator
resolveKeyGenerator
(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 Details
-
POSITION
public static final int POSITIONThe 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 managererrorHandler
- Cache error handlerasyncCacheErrorHandler
- Async cache error handlersioExecutor
- The executor to create tasksbeanContext
- The bean context to allow DI
-
-
Method Details
-
getOrder
public int getOrder()- Specified by:
getOrder
in interfaceio.micronaut.core.order.Ordered
-
intercept
-
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 invocationreturnType
- 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 invocationintercept
- The intercepted resultreturnTypeObject
- The return type of the method in MicronautrequiredType
- 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
Resolve the cache key generator from the give type.- Parameters:
type
- The key generator- Returns:
- The cache key generator
-
doContextProceed
- Parameters:
context
- the method invocation context- Returns:
- the proceed result
-