Top Description Fields Constructors Methods
org.springframework.cache.interceptor

public Class LoggingCacheErrorHandler

extends Object
implements CacheErrorHandler
Class Inheritance
All Implemented Interfaces
org.springframework.cache.interceptor.CacheErrorHandler
Imports
java.util.function.Supplier, org.apache.commons.logging.Log, .LogFactory, org.springframework.cache.Cache, org.springframework.lang.Nullable, org.springframework.util.Assert

A CacheErrorHandler implementation that logs error messages.

Can be used when underlying cache errors should be ignored.

Authors
Adam Ostrožlík, Stephane Nicoll, Vedran Pavic, Sam Brannen
Since
5.3.16

Field Summary

Modifier and TypeField and Description
private final Log
private final boolean

Constructor Summary

AccessConstructor and Description
public
LoggingCacheErrorHandler()

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

public
LoggingCacheErrorHandler(boolean
whether to log stack traces
logStackTraces
)

Create a LoggingCacheErrorHandler that uses the default logging category and the supplied logStackTraces flag.

public
LoggingCacheErrorHandler(Log
the logger to use
logger
,
boolean
whether to log stack traces
logStackTraces
)

Create a LoggingCacheErrorHandler that uses the supplied logger and logStackTraces flag.

public
LoggingCacheErrorHandler(String
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.
loggerName
,
boolean
whether to log stack traces
logStackTraces
)

Create a LoggingCacheErrorHandler that uses the supplied loggerName and logStackTraces flag.

Method Summary

Modifier and TypeMethod and Description
protected final Log

Returns:

the logger
getLogger
()

Get the logger for this LoggingCacheErrorHandler.

public void
handleCacheClearError(RuntimeException
the exception thrown by the cache provider
exception
,
Cache
the cache to clear
cache
)

Implements org.springframework.cache.interceptor.CacheErrorHandler.handleCacheClearError.

Handle the given runtime exception thrown by the cache provider when clearing the specified Cache, possibly rethrowing it as a fatal exception.
public void
handleCacheEvictError(RuntimeException
the exception thrown by the cache provider
exception
,
Cache
the cache
cache
,
Object
the key used to clear the item
key
)

Implements org.springframework.cache.interceptor.CacheErrorHandler.handleCacheEvictError.

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.
public void
handleCacheGetError(RuntimeException
the exception thrown by the cache provider
exception
,
Cache
the cache
cache
,
Object
the key used to get the item
key
)

Implements org.springframework.cache.interceptor.CacheErrorHandler.handleCacheGetError.

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.
public void
handleCachePutError(RuntimeException
the exception thrown by the cache provider
exception
,
Cache
the cache
cache
,
Object
the key used to update the item
key
,
Object
the value to associate with the key
value
)

Implements org.springframework.cache.interceptor.CacheErrorHandler.handleCachePutError.

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 final boolean

Returns:

true if this LoggingCacheErrorHandler logs stack traces
isLogStackTraces
()

Get the logStackTraces flag for this LoggingCacheErrorHandler.

protected void
logCacheError(Supplier<String>
the message supplier
messageSupplier
,
RuntimeException
the exception thrown by the cache provider
exception
)

Log the cache error message in the given supplier.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

loggerback to summary
private final Log logger
logStackTracesback to summary
private final boolean logStackTraces

Constructor Detail

LoggingCacheErrorHandlerback to summary
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".

LoggingCacheErrorHandlerback to summary
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:boolean

whether to log stack traces

Since
5.3.22
LoggingCacheErrorHandlerback to summary
public LoggingCacheErrorHandler(Log logger, boolean logStackTraces)

Create a LoggingCacheErrorHandler that uses the supplied logger and logStackTraces flag.

Parameters
logger:Log

the logger to use

logStackTraces:boolean

whether to log stack traces

LoggingCacheErrorHandlerback to summary
public LoggingCacheErrorHandler(String loggerName, boolean logStackTraces)

Create a LoggingCacheErrorHandler that uses the supplied loggerName and logStackTraces flag.

Parameters
loggerName:String

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:boolean

whether to log stack traces

Since
5.3.24
See Also
org.apache.commons.logging.LogFactory#getLog(String), java.util.logging.Logger#getLogger(String)

Method Detail

getLoggerback to summary
protected final Log getLogger()

Get the logger for this LoggingCacheErrorHandler.

Returns:Log

the logger

Since
5.3.22
handleCacheClearErrorback to summary
public void handleCacheClearError(RuntimeException exception, Cache cache)

Implements org.springframework.cache.interceptor.CacheErrorHandler.handleCacheClearError.

Doc from org.springframework.cache.interceptor.CacheErrorHandler.handleCacheClearError.

Handle the given runtime exception thrown by the cache provider when clearing the specified Cache, possibly rethrowing it as a fatal exception.

Parameters
exception:RuntimeException

the exception thrown by the cache provider

cache:Cache

the cache to clear

Annotations
@Override
handleCacheEvictErrorback to summary
public void handleCacheEvictError(RuntimeException exception, Cache cache, Object key)

Implements org.springframework.cache.interceptor.CacheErrorHandler.handleCacheEvictError.

Doc from org.springframework.cache.interceptor.CacheErrorHandler.handleCacheEvictError.

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.

Parameters
exception:RuntimeException

the exception thrown by the cache provider

cache:Cache

the cache

key:Object

the key used to clear the item

Annotations
@Override
handleCacheGetErrorback to summary
public void handleCacheGetError(RuntimeException exception, Cache cache, Object key)

Implements org.springframework.cache.interceptor.CacheErrorHandler.handleCacheGetError.

Doc from org.springframework.cache.interceptor.CacheErrorHandler.handleCacheGetError.

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.

Parameters
exception:RuntimeException

the exception thrown by the cache provider

cache:Cache

the cache

key:Object

the key used to get the item

Annotations
@Override
handleCachePutErrorback to summary
public void handleCachePutError(RuntimeException exception, Cache cache, Object key, Object value)

Implements org.springframework.cache.interceptor.CacheErrorHandler.handleCachePutError.

Doc from org.springframework.cache.interceptor.CacheErrorHandler.handleCachePutError.

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.

Parameters
exception:RuntimeException

the exception thrown by the cache provider

cache:Cache

the cache

key:Object

the key used to update the item

value:Object

the value to associate with the key

Annotations
@Override
isLogStackTracesback to summary
protected final boolean isLogStackTraces()

Get the logStackTraces flag for this LoggingCacheErrorHandler.

Returns:boolean

true if this LoggingCacheErrorHandler logs stack traces

Since
5.3.22
logCacheErrorback to summary
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:Supplier<String>

the message supplier

exception:RuntimeException

the exception thrown by the cache provider

Since
5.3.22
See Also
isLogStackTraces(), getLogger()