Class LoggingCacheErrorHandler

java.lang.Object
org.springframework.cache.interceptor.LoggingCacheErrorHandler
All Implemented Interfaces:
CacheErrorHandler

public class LoggingCacheErrorHandler extends Object implements CacheErrorHandler
A CacheErrorHandler implementation that logs error messages.

Can be used when underlying cache errors should be ignored.

Since:
5.3.16
Author:
Adam Ostrožlík, Stephane Nicoll, Vedran Pavic, Sam Brannen
  • Constructor Details

    • LoggingCacheErrorHandler

      public LoggingCacheErrorHandler()
      Create a LoggingCacheErrorHandler that uses the default logging category and does not log stack traces.

      The default logging category is "org.springframework.cache.interceptor.LoggingCacheErrorHandler".

    • LoggingCacheErrorHandler

      public LoggingCacheErrorHandler(boolean logStackTraces)
      Create a LoggingCacheErrorHandler that uses the default logging category and the supplied logStackTraces flag.

      The default logging category is "org.springframework.cache.interceptor.LoggingCacheErrorHandler".

      Parameters:
      logStackTraces - whether to log stack traces
      Since:
      5.3.22
    • LoggingCacheErrorHandler

      public LoggingCacheErrorHandler(Log logger, boolean logStackTraces)
      Create a LoggingCacheErrorHandler that uses the supplied logger and logStackTraces flag.
      Parameters:
      logger - the logger to use
      logStackTraces - whether to log stack traces
  • Method Details

    • handleCacheGetError

      public void handleCacheGetError(RuntimeException exception, Cache cache, Object key)
      Description copied from interface: CacheErrorHandler
      Handle the given runtime exception thrown by the cache provider when retrieving an item with the specified key, possibly rethrowing it as a fatal exception.
      Specified by:
      handleCacheGetError in interface CacheErrorHandler
      Parameters:
      exception - the exception thrown by the cache provider
      cache - the cache
      key - the key used to get the item
      See Also:
    • handleCachePutError

      public void handleCachePutError(RuntimeException exception, Cache cache, Object key, @Nullable Object value)
      Description copied from interface: CacheErrorHandler
      Handle the given runtime exception thrown by the cache provider when updating an item with the specified key and value, possibly rethrowing it as a fatal exception.
      Specified by:
      handleCachePutError in interface CacheErrorHandler
      Parameters:
      exception - the exception thrown by the cache provider
      cache - the cache
      key - the key used to update the item
      value - the value to associate with the key
      See Also:
    • handleCacheEvictError

      public void handleCacheEvictError(RuntimeException exception, Cache cache, Object key)
      Description copied from interface: CacheErrorHandler
      Handle the given runtime exception thrown by the cache provider when clearing an item with the specified key, possibly rethrowing it as a fatal exception.
      Specified by:
      handleCacheEvictError in interface CacheErrorHandler
      Parameters:
      exception - the exception thrown by the cache provider
      cache - the cache
      key - the key used to clear the item
    • handleCacheClearError

      public void handleCacheClearError(RuntimeException exception, Cache cache)
      Description copied from interface: CacheErrorHandler
      Handle the given runtime exception thrown by the cache provider when clearing the specified Cache, possibly rethrowing it as a fatal exception.
      Specified by:
      handleCacheClearError in interface CacheErrorHandler
      Parameters:
      exception - the exception thrown by the cache provider
      cache - the cache to clear
    • getLogger

      protected final Log getLogger()
      Get the logger for this LoggingCacheErrorHandler.
      Returns:
      the logger
      Since:
      5.3.22
    • isLogStackTraces

      protected final boolean isLogStackTraces()
      Get the logStackTraces flag for this LoggingCacheErrorHandler.
      Returns:
      true if this LoggingCacheErrorHandler logs stack traces
      Since:
      5.3.22
    • logCacheError

      protected void logCacheError(Supplier<String> messageSupplier, RuntimeException exception)
      Log the cache error message in the given supplier.

      If isLogStackTraces() is true, the given exception will be logged as well.

      The default implementation logs the message as a warning.

      Parameters:
      messageSupplier - the message supplier
      exception - the exception thrown by the cache provider
      Since:
      5.3.22
      See Also: