Class CacheRequestHandlerAdvice
java.lang.Object
org.springframework.integration.context.IntegrationObjectSupport
org.springframework.integration.handler.advice.AbstractRequestHandlerAdvice
org.springframework.integration.handler.advice.CacheRequestHandlerAdvice
- All Implemented Interfaces:
Advice
,Interceptor
,MethodInterceptor
,Aware
,BeanFactoryAware
,BeanNameAware
,InitializingBean
,SmartInitializingSingleton
,ApplicationContextAware
,ComponentSourceAware
,ExpressionCapable
,NamedComponent
public class CacheRequestHandlerAdvice
extends AbstractRequestHandlerAdvice
implements SmartInitializingSingleton
The
AbstractRequestHandlerAdvice
implementation for caching
AbstractReplyProducingMessageHandler.RequestHandler#handleRequestMessage(Message)
results.
Supports all the cache operations - cacheable, put, evict.
By default, only cacheable is applied for the provided cacheNames
.
The default cache key
is payload
of the request message.- Since:
- 5.2
- Author:
- Artem Bilan, Ngoc Nhan
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class org.springframework.integration.handler.advice.AbstractRequestHandlerAdvice
AbstractRequestHandlerAdvice.ExecutionCallback, AbstractRequestHandlerAdvice.ThrowableHolderException
-
Field Summary
Fields inherited from class org.springframework.integration.context.IntegrationObjectSupport
EXPRESSION_PARSER, logger
-
Constructor Summary
ConstructorDescriptionCacheRequestHandlerAdvice
(String... cacheNamesArg) Create aCacheRequestHandlerAdvice
instance based on the provided name of caches andCacheableOperation
as default one. -
Method Summary
Modifier and TypeMethodDescriptionvoid
protected Object
doInvoke
(AbstractRequestHandlerAdvice.ExecutionCallback callback, Object target, Message<?> message) Subclasses implement this method to apply behavior to theMessageHandler
.protected void
onInit()
Subclasses may implement this for initialization logic.void
setCacheManager
(CacheManager cacheManager) Configure a commonCacheManager
if someCacheOperation
comes without it.void
setCacheOperations
(CacheOperation... cacheOperations) Configure a set ofCacheOperation
which are going to be applied to theAbstractReplyProducingMessageHandler.RequestHandler#handleRequestMessage(Message)
method viaCacheRequestHandlerAdvice.IntegrationCacheAspect
.void
setCacheResolver
(CacheResolver cacheResolver) Configure a commonCacheResolver
if someCacheOperation
comes without it.void
setErrorHandler
(CacheErrorHandler errorHandler) Set theCacheErrorHandler
instance to use to handle errors thrown by the cache provider.void
setKeyExpression
(Expression keyExpression) Configure a SpEL expression to evaluate a cache key at runtime against a request message.void
setKeyExpressionString
(String keyExpression) Configure an expression in SpEL style to evaluate a cache key at runtime against a request message.void
setKeyFunction
(Function<Message<?>, ?> keyFunction) Configure aFunction
to evaluate a cache key at runtime against a request message.Methods inherited from class org.springframework.integration.handler.advice.AbstractRequestHandlerAdvice
invoke, unwrapExceptionIfNecessary, unwrapThrowableIfNecessary
Methods inherited from class org.springframework.integration.context.IntegrationObjectSupport
afterPropertiesSet, extractTypeIfPossible, generateId, getApplicationContext, getApplicationContextId, getBeanDescription, getBeanFactory, getBeanName, getChannelResolver, getComponentDescription, getComponentName, getComponentSource, getComponentType, getConversionService, getExpression, getIntegrationProperties, getMessageBuilderFactory, getTaskScheduler, isInitialized, setApplicationContext, setBeanFactory, setBeanName, setChannelResolver, setComponentDescription, setComponentName, setComponentSource, setConversionService, setMessageBuilderFactory, setPrimaryExpression, setTaskScheduler, toString
-
Constructor Details
-
CacheRequestHandlerAdvice
Create aCacheRequestHandlerAdvice
instance based on the provided name of caches andCacheableOperation
as default one. This can be overridden by thesetCacheOperations(org.springframework.cache.interceptor.CacheOperation...)
.- Parameters:
cacheNamesArg
- the name of caches to use in the advice.- See Also:
-
-
Method Details
-
setCacheOperations
Configure a set ofCacheOperation
which are going to be applied to theAbstractReplyProducingMessageHandler.RequestHandler#handleRequestMessage(Message)
method viaCacheRequestHandlerAdvice.IntegrationCacheAspect
. This is similar to the technique provided by theCaching
annotation.- Parameters:
cacheOperations
- the array ofCacheOperation
to use.- See Also:
-
setCacheManager
Configure a commonCacheManager
if someCacheOperation
comes without it. SeeCacheConfig
annotation for similar approach.- Parameters:
cacheManager
- theCacheManager
to use.- See Also:
-
setCacheResolver
Configure a commonCacheResolver
if someCacheOperation
comes without it. SeeCacheConfig
for similar approach.- Parameters:
cacheResolver
- theCacheResolver
to use.- See Also:
-
setErrorHandler
Set theCacheErrorHandler
instance to use to handle errors thrown by the cache provider.- Parameters:
errorHandler
- theCacheErrorHandler
to use.- See Also:
-
setKeyExpressionString
Configure an expression in SpEL style to evaluate a cache key at runtime against a request message.- Parameters:
keyExpression
- the expression to use for cache key generation.
-
setKeyFunction
Configure aFunction
to evaluate a cache key at runtime against a request message.- Parameters:
keyFunction
- theFunction
to use for cache key generation.
-
setKeyExpression
Configure a SpEL expression to evaluate a cache key at runtime against a request message.- Parameters:
keyExpression
- the expression to use for cache key generation.
-
afterSingletonsInstantiated
public void afterSingletonsInstantiated()- Specified by:
afterSingletonsInstantiated
in interfaceSmartInitializingSingleton
-
onInit
protected void onInit()Description copied from class:IntegrationObjectSupport
Subclasses may implement this for initialization logic.- Overrides:
onInit
in classIntegrationObjectSupport
-
doInvoke
@Nullable protected Object doInvoke(AbstractRequestHandlerAdvice.ExecutionCallback callback, Object target, Message<?> message) Description copied from class:AbstractRequestHandlerAdvice
Subclasses implement this method to apply behavior to theMessageHandler
.callback.execute() invokes the handler method and returns its result, or null.
- Specified by:
doInvoke
in classAbstractRequestHandlerAdvice
- Parameters:
callback
- Subclasses invoke the execute() method on this interface to invoke the handler method.target
- The target handler.message
- The message that will be sent to the handler.- Returns:
- the result after invoking the
MessageHandler
.
-