Class 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
  • Constructor Details

  • Method Details

    • setCacheOperations

      public void setCacheOperations​(org.springframework.cache.interceptor.CacheOperation... cacheOperations)
      Configure a set of CacheOperation which are going to be applied to the AbstractReplyProducingMessageHandler.RequestHandler#handleRequestMessage(Message) method via CacheRequestHandlerAdvice.IntegrationCacheAspect. This is similar to the technique provided by the Caching annotation.
      Parameters:
      cacheOperations - the array of CacheOperation to use.
      See Also:
      Caching
    • setCacheManager

      public void setCacheManager​(org.springframework.cache.CacheManager cacheManager)
      Configure a common CacheManager if some CacheOperation comes without it. See CacheConfig annotation for similar approach.
      Parameters:
      cacheManager - the CacheManager to use.
      See Also:
      CacheConfig
    • setCacheResolver

      public void setCacheResolver​(org.springframework.cache.interceptor.CacheResolver cacheResolver)
      Configure a common CacheResolver if some CacheOperation comes without it. See CacheConfig for similar approach.
      Parameters:
      cacheResolver - the CacheResolver to use.
      See Also:
      CacheConfig
    • setErrorHandler

      public void setErrorHandler​(org.springframework.cache.interceptor.CacheErrorHandler errorHandler)
      Set the CacheErrorHandler instance to use to handle errors thrown by the cache provider.
      Parameters:
      errorHandler - the CacheErrorHandler 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 a Function to evaluate a cache key at runtime against a request message.
      Parameters:
      keyFunction - the Function 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 interface org.springframework.beans.factory.SmartInitializingSingleton
    • onInit

      protected void onInit()
      Description copied from class: IntegrationObjectSupport
      Subclasses may implement this for initialization logic.
      Overrides:
      onInit in class IntegrationObjectSupport
    • 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 the MessageHandler.

      callback.execute() invokes the handler method and returns its result, or null.

      Specified by:
      doInvoke in 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.