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:
org.aopalliance.aop.Advice
,org.aopalliance.intercept.Interceptor
,org.aopalliance.intercept.MethodInterceptor
,org.springframework.beans.factory.Aware
,org.springframework.beans.factory.BeanFactoryAware
,org.springframework.beans.factory.BeanNameAware
,org.springframework.beans.factory.InitializingBean
,org.springframework.beans.factory.SmartInitializingSingleton
,org.springframework.context.ApplicationContextAware
,ExpressionCapable
,NamedComponent
public class CacheRequestHandlerAdvice extends AbstractRequestHandlerAdvice implements org.springframework.beans.factory.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
- See Also:
CacheAspectSupport
,CacheOperation
-
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
Constructors Constructor Description CacheRequestHandlerAdvice(java.lang.String... cacheNamesArg)
Create aCacheRequestHandlerAdvice
instance based on the provided name of caches andCacheableOperation
as default one. -
Method Summary
Modifier and Type Method Description void
afterSingletonsInstantiated()
protected java.lang.Object
doInvoke(AbstractRequestHandlerAdvice.ExecutionCallback callback, java.lang.Object target, org.springframework.messaging.Message<?> message)
Subclasses implement this method to apply behavior to theMessageHandler
.protected void
onInit()
Subclasses may implement this for initialization logic.void
setCacheManager(org.springframework.cache.CacheManager cacheManager)
Configure a commonCacheManager
if someCacheOperation
comes without it.void
setCacheOperations(org.springframework.cache.interceptor.CacheOperation... cacheOperations)
Configure a set ofCacheOperation
which are going to be applied to theAbstractReplyProducingMessageHandler.RequestHandler#handleRequestMessage(Message)
method viaCacheRequestHandlerAdvice.IntegrationCacheAspect
.void
setCacheResolver(org.springframework.cache.interceptor.CacheResolver cacheResolver)
Configure a commonCacheResolver
if someCacheOperation
comes without it.void
setErrorHandler(org.springframework.cache.interceptor.CacheErrorHandler errorHandler)
Set theCacheErrorHandler
instance to use to handle errors thrown by the cache provider.void
setKeyExpression(org.springframework.expression.Expression keyExpression)
Configure a SpEL expression to evaluate a cache key at runtime against a request message.void
setKeyExpressionString(java.lang.String keyExpression)
Configure an expression in SpEL style to evaluate a cache key at runtime against a request message.void
setKeyFunction(java.util.function.Function<org.springframework.messaging.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, getComponentName, getComponentType, getConversionService, getExpression, getIntegrationProperties, getIntegrationProperty, getMessageBuilderFactory, getTaskScheduler, isInitialized, setApplicationContext, setBeanFactory, setBeanName, setChannelResolver, setComponentName, setConversionService, setMessageBuilderFactory, setPrimaryExpression, setTaskScheduler, toString
-
Constructor Details
-
CacheRequestHandlerAdvice
public CacheRequestHandlerAdvice(java.lang.String... cacheNamesArg)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:
setCacheOperations(org.springframework.cache.interceptor.CacheOperation...)
-
-
Method Details
-
setCacheOperations
public void setCacheOperations(org.springframework.cache.interceptor.CacheOperation... cacheOperations)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:
Caching
-
setCacheManager
public void setCacheManager(org.springframework.cache.CacheManager cacheManager)Configure a commonCacheManager
if someCacheOperation
comes without it. SeeCacheConfig
annotation for similar approach.- Parameters:
cacheManager
- theCacheManager
to use.- See Also:
CacheConfig
-
setCacheResolver
public void setCacheResolver(org.springframework.cache.interceptor.CacheResolver cacheResolver)Configure a commonCacheResolver
if someCacheOperation
comes without it. SeeCacheConfig
for similar approach.- Parameters:
cacheResolver
- theCacheResolver
to use.- See Also:
CacheConfig
-
setErrorHandler
public void setErrorHandler(org.springframework.cache.interceptor.CacheErrorHandler errorHandler)Set theCacheErrorHandler
instance to use to handle errors thrown by the cache provider.- Parameters:
errorHandler
- theCacheErrorHandler
to use.- See Also:
AbstractCacheInvoker.setErrorHandler(CacheErrorHandler)
-
setKeyExpressionString
public void setKeyExpressionString(java.lang.String keyExpression)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
public void setKeyFunction(java.util.function.Function<org.springframework.messaging.Message<?>,?> keyFunction)Configure aFunction
to evaluate a cache key at runtime against a request message.- Parameters:
keyFunction
- theFunction
to use for cache key generation.
-
setKeyExpression
public void setKeyExpression(org.springframework.expression.Expression keyExpression)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 interfaceorg.springframework.beans.factory.SmartInitializingSingleton
-
onInit
protected void onInit()Description copied from class:IntegrationObjectSupport
Subclasses may implement this for initialization logic.- Overrides:
onInit
in classIntegrationObjectSupport
-
doInvoke
@Nullable protected java.lang.Object doInvoke(AbstractRequestHandlerAdvice.ExecutionCallback callback, java.lang.Object target, org.springframework.messaging.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
.
-