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
ConstructorsConstructorDescriptionCreate aLoggingCacheErrorHandlerthat uses the default logging category and does not log stack traces.LoggingCacheErrorHandler(boolean logStackTraces) Create aLoggingCacheErrorHandlerthat uses the default logging category and the suppliedlogStackTracesflag.LoggingCacheErrorHandler(String loggerName, boolean logStackTraces) Create aLoggingCacheErrorHandlerthat uses the suppliedloggerNameandlogStackTracesflag.LoggingCacheErrorHandler(org.apache.commons.logging.Log logger, boolean logStackTraces) Create aLoggingCacheErrorHandlerthat uses the suppliedloggerandlogStackTracesflag. -
Method Summary
Modifier and TypeMethodDescriptionprotected final org.apache.commons.logging.LogGet the logger for thisLoggingCacheErrorHandler.voidhandleCacheClearError(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.voidhandleCacheEvictError(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.voidhandleCacheGetError(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.voidhandleCachePutError(RuntimeException exception, Cache cache, Object key, @Nullable Object value) Handle the given runtime exception thrown by the cache provider when updating an item with the specifiedkeyandvalue, possibly rethrowing it as a fatal exception.protected final booleanGet thelogStackTracesflag for thisLoggingCacheErrorHandler.protected voidlogCacheError(Supplier<String> messageSupplier, RuntimeException exception) Log the cache error message in the given supplier.
-
Constructor Details
-
LoggingCacheErrorHandler
public LoggingCacheErrorHandler()Create aLoggingCacheErrorHandlerthat 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 aLoggingCacheErrorHandlerthat uses the default logging category and the suppliedlogStackTracesflag.The default logging category is "
org.springframework.cache.interceptor.LoggingCacheErrorHandler".- Parameters:
logStackTraces- whether to log stack traces- Since:
- 5.3.22
-
LoggingCacheErrorHandler
public LoggingCacheErrorHandler(org.apache.commons.logging.Log logger, boolean logStackTraces) Create aLoggingCacheErrorHandlerthat uses the suppliedloggerandlogStackTracesflag.- Parameters:
logger- the logger to uselogStackTraces- whether to log stack traces
-
LoggingCacheErrorHandler
Create aLoggingCacheErrorHandlerthat uses the suppliedloggerNameandlogStackTracesflag.- 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:
-
-
Method Details
-
handleCacheGetError
Description copied from interface:CacheErrorHandlerHandle 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:
handleCacheGetErrorin 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:CacheErrorHandlerHandle the given runtime exception thrown by the cache provider when updating an item with the specifiedkeyandvalue, possibly rethrowing it as a fatal exception.- Specified by:
handleCachePutErrorin 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:CacheErrorHandlerHandle 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:
handleCacheEvictErrorin interfaceCacheErrorHandler- Parameters:
exception- the exception thrown by the cache providercache- the cachekey- the key used to clear the item
-
handleCacheClearError
Description copied from interface:CacheErrorHandlerHandle the given runtime exception thrown by the cache provider when clearing the specifiedCache, possibly rethrowing it as a fatal exception.- Specified by:
handleCacheClearErrorin interfaceCacheErrorHandler- Parameters:
exception- the exception thrown by the cache providercache- the cache to clear
-
getLogger
protected final org.apache.commons.logging.Log getLogger()Get the logger for thisLoggingCacheErrorHandler.- Returns:
- the logger
- Since:
- 5.3.22
-
isLogStackTraces
protected final boolean isLogStackTraces()Get thelogStackTracesflag for thisLoggingCacheErrorHandler.- Returns:
trueif thisLoggingCacheErrorHandlerlogs stack traces- Since:
- 5.3.22
-
logCacheError
Log the cache error message in the given supplier.If
isLogStackTraces()istrue, the givenexceptionwill 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:
-