public class LoggingCacheErrorHandler extends Object implements CacheErrorHandler
CacheErrorHandler
implementation that logs error messages.
Can be used when underlying cache errors should be ignored.
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)
|
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.
|
public LoggingCacheErrorHandler()
LoggingCacheErrorHandler
that uses the default logging
category and does not log stack traces.
The default logging category is
"org.springframework.cache.interceptor.LoggingCacheErrorHandler
".
public LoggingCacheErrorHandler(boolean logStackTraces)
LoggingCacheErrorHandler
that uses the default logging
category and the supplied logStackTraces
flag.
The default logging category is
"org.springframework.cache.interceptor.LoggingCacheErrorHandler
".
logStackTraces
- whether to log stack tracespublic LoggingCacheErrorHandler(Log logger, boolean logStackTraces)
logger
- the logger to uselogStackTraces
- whether to log stack tracespublic void handleCacheGetError(RuntimeException exception, Cache cache, Object key)
CacheErrorHandler
key
, possibly
rethrowing it as a fatal exception.handleCacheGetError
in interface CacheErrorHandler
exception
- the exception thrown by the cache providercache
- the cachekey
- the key used to get the itemCache.get(Object)
public void handleCachePutError(RuntimeException exception, Cache cache, Object key, @Nullable Object value)
CacheErrorHandler
key
and value
,
possibly rethrowing it as a fatal exception.handleCachePutError
in interface CacheErrorHandler
exception
- the exception thrown by the cache providercache
- the cachekey
- the key used to update the itemvalue
- the value to associate with the keyCache.put(Object, Object)
public void handleCacheEvictError(RuntimeException exception, Cache cache, Object key)
CacheErrorHandler
key
, possibly rethrowing
it as a fatal exception.handleCacheEvictError
in interface CacheErrorHandler
exception
- the exception thrown by the cache providercache
- the cachekey
- the key used to clear the itempublic void handleCacheClearError(RuntimeException exception, Cache cache)
CacheErrorHandler
Cache
, possibly rethrowing it as a
fatal exception.handleCacheClearError
in interface CacheErrorHandler
exception
- the exception thrown by the cache providercache
- the cache to clearprotected final Log getLogger()
LoggingCacheErrorHandler
.protected final boolean isLogStackTraces()
logStackTraces
flag for this LoggingCacheErrorHandler
.true
if this LoggingCacheErrorHandler
logs stack tracesprotected void logCacheError(Supplier<String> messageSupplier, RuntimeException exception)
If isLogStackTraces()
is true
, the given
exception
will be logged as well.
The default implementation logs the message as a warning.
messageSupplier
- the message supplierexception
- the exception thrown by the cache providerisLogStackTraces()
,
getLogger()