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,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
- 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(String... cacheNamesArg)Create aCacheRequestHandlerAdviceinstance based on the provided name of caches andCacheableOperationas default one. -
Method Summary
Modifier and Type Method Description voidafterSingletonsInstantiated()protected ObjectdoInvoke(AbstractRequestHandlerAdvice.ExecutionCallback callback, Object target, Message<?> message)Subclasses implement this method to apply behavior to theMessageHandler.protected voidonInit()Subclasses may implement this for initialization logic.voidsetCacheManager(CacheManager cacheManager)Configure a commonCacheManagerif someCacheOperationcomes without it.voidsetCacheOperations(CacheOperation... cacheOperations)Configure a set ofCacheOperationwhich are going to be applied to theAbstractReplyProducingMessageHandler.RequestHandler#handleRequestMessage(Message)method viaCacheRequestHandlerAdvice.IntegrationCacheAspect.voidsetCacheResolver(CacheResolver cacheResolver)Configure a commonCacheResolverif someCacheOperationcomes without it.voidsetErrorHandler(CacheErrorHandler errorHandler)Set theCacheErrorHandlerinstance to use to handle errors thrown by the cache provider.voidsetKeyExpression(Expression keyExpression)Configure a SpEL expression to evaluate a cache key at runtime against a request message.voidsetKeyExpressionString(String keyExpression)Configure an expression in SpEL style to evaluate a cache key at runtime against a request message.voidsetKeyFunction(Function<Message<?>,?> keyFunction)Configure aFunctionto evaluate a cache key at runtime against a request message.Methods inherited from class org.springframework.integration.handler.advice.AbstractRequestHandlerAdvice
invoke, unwrapExceptionIfNecessary, unwrapThrowableIfNecessaryMethods 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
Create aCacheRequestHandlerAdviceinstance based on the provided name of caches andCacheableOperationas 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
Configure a set ofCacheOperationwhich are going to be applied to theAbstractReplyProducingMessageHandler.RequestHandler#handleRequestMessage(Message)method viaCacheRequestHandlerAdvice.IntegrationCacheAspect. This is similar to the technique provided by theCachingannotation.- Parameters:
cacheOperations- the array ofCacheOperationto use.- See Also:
Caching
-
setCacheManager
Configure a commonCacheManagerif someCacheOperationcomes without it. SeeCacheConfigannotation for similar approach.- Parameters:
cacheManager- theCacheManagerto use.- See Also:
CacheConfig
-
setCacheResolver
Configure a commonCacheResolverif someCacheOperationcomes without it. SeeCacheConfigfor similar approach.- Parameters:
cacheResolver- theCacheResolverto use.- See Also:
CacheConfig
-
setErrorHandler
Set theCacheErrorHandlerinstance to use to handle errors thrown by the cache provider.- Parameters:
errorHandler- theCacheErrorHandlerto use.- See Also:
AbstractCacheInvoker.setErrorHandler(CacheErrorHandler)
-
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 aFunctionto evaluate a cache key at runtime against a request message.- Parameters:
keyFunction- theFunctionto 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:
afterSingletonsInstantiatedin interfaceSmartInitializingSingleton
-
onInit
protected void onInit()Description copied from class:IntegrationObjectSupportSubclasses may implement this for initialization logic.- Overrides:
onInitin classIntegrationObjectSupport
-
doInvoke
@Nullable protected Object doInvoke(AbstractRequestHandlerAdvice.ExecutionCallback callback, Object target, Message<?> message)Description copied from class:AbstractRequestHandlerAdviceSubclasses implement this method to apply behavior to theMessageHandler.callback.execute() invokes the handler method and returns its result, or null.
- Specified by:
doInvokein 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.
-