public class CacheRequestHandlerAdvice extends AbstractRequestHandlerAdvice implements SmartInitializingSingleton
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.CacheAspectSupport
,
CacheOperation
AbstractRequestHandlerAdvice.ExecutionCallback, AbstractRequestHandlerAdvice.ThrowableHolderException
EXPRESSION_PARSER, logger
Constructor and Description |
---|
CacheRequestHandlerAdvice(String... cacheNamesArg)
Create a
CacheRequestHandlerAdvice instance based on the provided name of caches
and CacheableOperation as default one. |
Modifier and Type | Method and Description |
---|---|
void |
afterSingletonsInstantiated() |
protected Object |
doInvoke(AbstractRequestHandlerAdvice.ExecutionCallback callback,
Object target,
Message<?> message)
Subclasses implement this method to apply behavior to the
MessageHandler . |
protected void |
onInit()
Subclasses may implement this for initialization logic.
|
void |
setCacheManager(CacheManager cacheManager)
Configure a common
CacheManager if some CacheOperation comes without it. |
void |
setCacheOperations(CacheOperation... cacheOperations)
Configure a set of
CacheOperation which are going to be applied to the
AbstractReplyProducingMessageHandler.RequestHandler#handleRequestMessage(Message)
method via IntegrationCacheAspect . |
void |
setCacheResolver(CacheResolver cacheResolver)
Configure a common
CacheResolver if some CacheOperation comes without it. |
void |
setErrorHandler(CacheErrorHandler errorHandler)
Set the
CacheErrorHandler 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(java.util.function.Function<Message<?>,?> keyFunction)
Configure a
Function to evaluate a cache key at runtime
against a request message. |
invoke, unwrapExceptionIfNecessary, unwrapThrowableIfNecessary
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
public CacheRequestHandlerAdvice(String... cacheNamesArg)
CacheRequestHandlerAdvice
instance based on the provided name of caches
and CacheableOperation
as default one.
This can be overridden by the setCacheOperations(org.springframework.cache.interceptor.CacheOperation...)
.cacheNamesArg
- the name of caches to use in the advice.setCacheOperations(org.springframework.cache.interceptor.CacheOperation...)
public void setCacheOperations(CacheOperation... cacheOperations)
CacheOperation
which are going to be applied to the
AbstractReplyProducingMessageHandler.RequestHandler#handleRequestMessage(Message)
method via IntegrationCacheAspect
.
This is similar to the technique provided by the
Caching
annotation.cacheOperations
- the array of CacheOperation
to use.Caching
public void setCacheManager(CacheManager cacheManager)
CacheManager
if some CacheOperation
comes without it.
See CacheConfig
annotation for similar approach.cacheManager
- the CacheManager
to use.CacheConfig
public void setCacheResolver(CacheResolver cacheResolver)
CacheResolver
if some CacheOperation
comes without it.
See CacheConfig
for similar approach.cacheResolver
- the CacheResolver
to use.CacheConfig
public void setErrorHandler(CacheErrorHandler errorHandler)
CacheErrorHandler
instance to use to handle errors
thrown by the cache provider.errorHandler
- the CacheErrorHandler
to use.AbstractCacheInvoker.setErrorHandler(CacheErrorHandler)
public void setKeyExpressionString(String keyExpression)
keyExpression
- the expression to use for cache key generation.public void setKeyFunction(java.util.function.Function<Message<?>,?> keyFunction)
Function
to evaluate a cache key at runtime
against a request message.keyFunction
- the Function
to use for cache key generation.public void setKeyExpression(Expression keyExpression)
keyExpression
- the expression to use for cache key generation.public void afterSingletonsInstantiated()
afterSingletonsInstantiated
in interface SmartInitializingSingleton
protected void onInit()
IntegrationObjectSupport
onInit
in class IntegrationObjectSupport
@Nullable protected Object doInvoke(AbstractRequestHandlerAdvice.ExecutionCallback callback, Object target, Message<?> message)
AbstractRequestHandlerAdvice
MessageHandler
.
callback.execute() invokes the handler method and returns its result, or null.
doInvoke
in class AbstractRequestHandlerAdvice
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.MessageHandler
.