Class LoggingCacheErrorHandler
java.lang.Object
org.springframework.cache.interceptor.LoggingCacheErrorHandler
- All Implemented Interfaces:
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
ConstructorDescriptionCreate aLoggingCacheErrorHandler
that uses the default logging category and does not log stack traces.LoggingCacheErrorHandler
(boolean logStackTraces) Create aLoggingCacheErrorHandler
that uses the default logging category and the suppliedlogStackTraces
flag.LoggingCacheErrorHandler
(Log logger, boolean logStackTraces) -
Method Summary
Modifier and TypeMethodDescriptionprotected final Log
Get the logger for thisLoggingCacheErrorHandler
.void
handleCacheClearError
(RuntimeException exception, Cache cache) Handle the given runtime exception thrown by the cache provider when clearing the specifiedCache
, 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 specifiedkey
, 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 specifiedkey
, 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 specifiedkey
andvalue
, possibly rethrowing it as a fatal exception.protected final boolean
Get thelogStackTraces
flag for thisLoggingCacheErrorHandler
.protected void
logCacheError
(Supplier<String> messageSupplier, RuntimeException exception) Log the cache error message in the given supplier.
-
Constructor Details
-
LoggingCacheErrorHandler
public LoggingCacheErrorHandler()Create aLoggingCacheErrorHandler
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 aLoggingCacheErrorHandler
that uses the default logging category and the suppliedlogStackTraces
flag.The default logging category is "
org.springframework.cache.interceptor.LoggingCacheErrorHandler
".- Parameters:
logStackTraces
- whether to log stack traces- Since:
- 5.3.22
-
LoggingCacheErrorHandler
- Parameters:
logger
- the logger to uselogStackTraces
- whether to log stack traces
-
-
Method Details
-
handleCacheGetError
Description copied from interface:CacheErrorHandler
Handle the given runtime exception thrown by the cache provider when retrieving an item with the specifiedkey
, possibly rethrowing it as a fatal exception.- Specified by:
handleCacheGetError
in interfaceCacheErrorHandler
- Parameters:
exception
- the exception thrown by the cache providercache
- the cachekey
- 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 specifiedkey
andvalue
, possibly rethrowing it as a fatal exception.- Specified by:
handleCachePutError
in interfaceCacheErrorHandler
- Parameters:
exception
- the exception thrown by the cache providercache
- the cachekey
- the key used to update the itemvalue
- the value to associate with the key- See Also:
-
handleCacheEvictError
Description copied from interface:CacheErrorHandler
Handle the given runtime exception thrown by the cache provider when clearing an item with the specifiedkey
, possibly rethrowing it as a fatal exception.- Specified by:
handleCacheEvictError
in interfaceCacheErrorHandler
- Parameters:
exception
- the exception thrown by the cache providercache
- the cachekey
- the key used to clear the item
-
handleCacheClearError
Description copied from interface:CacheErrorHandler
Handle the given runtime exception thrown by the cache provider when clearing the specifiedCache
, possibly rethrowing it as a fatal exception.- Specified by:
handleCacheClearError
in interfaceCacheErrorHandler
- Parameters:
exception
- the exception thrown by the cache providercache
- the cache to clear
-
getLogger
Get the logger for thisLoggingCacheErrorHandler
.- Returns:
- the logger
- Since:
- 5.3.22
-
isLogStackTraces
protected final boolean isLogStackTraces()Get thelogStackTraces
flag for thisLoggingCacheErrorHandler
.- Returns:
true
if thisLoggingCacheErrorHandler
logs stack traces- Since:
- 5.3.22
-
logCacheError
Log the cache error message in the given supplier.If
isLogStackTraces()
istrue
, the givenexception
will be logged as well.The default implementation logs the message as a warning.
- Parameters:
messageSupplier
- the message supplierexception
- the exception thrown by the cache provider- Since:
- 5.3.22
- See Also:
-