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:
- 
Nested Class SummaryNested classes/interfaces inherited from class org.springframework.integration.handler.advice.AbstractRequestHandlerAdviceAbstractRequestHandlerAdvice.ExecutionCallback, AbstractRequestHandlerAdvice.ThrowableHolderException
- 
Field SummaryFields inherited from class org.springframework.integration.context.IntegrationObjectSupportEXPRESSION_PARSER, logger
- 
Constructor SummaryConstructorsConstructorDescriptionCacheRequestHandlerAdvice(String... cacheNamesArg) Create aCacheRequestHandlerAdviceinstance based on the provided name of caches andCacheableOperationas default one.
- 
Method SummaryModifier and TypeMethodDescriptionvoidprotected 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.AbstractRequestHandlerAdviceinvoke, unwrapExceptionIfNecessary, unwrapThrowableIfNecessaryMethods inherited from class org.springframework.integration.context.IntegrationObjectSupportafterPropertiesSet, 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- 
CacheRequestHandlerAdviceCreate 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:
 
 
- 
- 
Method Details- 
setCacheOperationsConfigure 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 of- CacheOperationto use.
- See Also:
 
- 
setCacheManagerConfigure a commonCacheManagerif someCacheOperationcomes without it. SeeCacheConfigannotation for similar approach.- Parameters:
- cacheManager- the- CacheManagerto use.
- See Also:
 
- 
setCacheResolverConfigure a commonCacheResolverif someCacheOperationcomes without it. SeeCacheConfigfor similar approach.- Parameters:
- cacheResolver- the- CacheResolverto use.
- See Also:
 
- 
setErrorHandlerSet theCacheErrorHandlerinstance to use to handle errors thrown by the cache provider.- Parameters:
- errorHandler- the- CacheErrorHandlerto use.
- See Also:
 
- 
setKeyExpressionStringConfigure 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.
 
- 
setKeyFunctionConfigure aFunctionto evaluate a cache key at runtime against a request message.- Parameters:
- keyFunction- the- Functionto use for cache key generation.
 
- 
setKeyExpressionConfigure a SpEL expression to evaluate a cache key at runtime against a request message.- Parameters:
- keyExpression- the expression to use for cache key generation.
 
- 
afterSingletonsInstantiatedpublic void afterSingletonsInstantiated()- Specified by:
- afterSingletonsInstantiatedin interface- SmartInitializingSingleton
 
- 
onInitprotected void onInit()Description copied from class:IntegrationObjectSupportSubclasses may implement this for initialization logic.- Overrides:
- onInitin class- IntegrationObjectSupport
 
- 
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 class- AbstractRequestHandlerAdvice
- 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.
 
 
-