org.springframework.cache.interceptor

## 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 Summary

    Constructors
    Constructor and Description
    `LoggingCacheErrorHandler()` Create a `LoggingCacheErrorHandler` that uses the default logging category and does not log stack traces.
    `LoggingCacheErrorHandler(boolean logStackTraces)` Create a `LoggingCacheErrorHandler` that uses the default logging category and the supplied `logStackTraces` flag.
    `LoggingCacheErrorHandler(Log logger, boolean logStackTraces)` Create a `LoggingCacheErrorHandler` that uses the supplied `logger` and `logStackTraces` flag.
    `LoggingCacheErrorHandler(String loggerName, boolean logStackTraces)` Create a `LoggingCacheErrorHandler` that uses the supplied `loggerName` and `logStackTraces` flag.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected Log` | `getLogger()` Get the logger for this `LoggingCacheErrorHandler`.
    `void` | `handleCacheClearError(RuntimeException exception, Cache cache)` Handle the given runtime exception thrown by the cache provider when clearing the specified `Cache`, possibly rethrowing it as a fatal exception.
    `void` | `handleCacheEvictError(RuntimeException exception, Cache cache, Object key)` 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.
    `void` | `handleCacheGetError(RuntimeException exception, Cache cache, Object key)` 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.
    `void` | `handleCachePutError(RuntimeException exception, Cache cache, Object key, Object value)` 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.
    `protected boolean` | `isLogStackTraces()` Get the `logStackTraces` flag for this `LoggingCacheErrorHandler`.
    `protected void` | `logCacheError(Supplier<String> messageSupplier, RuntimeException exception)` Log the cache error message in the given supplier.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### 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

    - #### LoggingCacheErrorHandler

          public LoggingCacheErrorHandler(String loggerName,
                                          boolean logStackTraces)

      Create a `LoggingCacheErrorHandler` that uses the supplied `loggerName` and `logStackTraces` flag.
      Parameters:
        `loggerName` - the name of the logger to use. The name will be passed to the underlying logger implementation through Commons Logging, getting interpreted as log category according to the logger's configuration.
        `logStackTraces` - whether to log stack traces
      Since:
        5.3.24
      See Also:
        `LogFactory.getLog(String)`, `Logger.getLogger(String)`

  - ### Method Detail

    - #### 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:
        `Cache.get(Object)`

    - #### 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:
        `Cache.put(Object, Object)`

    - #### 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:
        `isLogStackTraces()`, `getLogger()`