Package org.springframework.cache.interceptor

# Interface CacheErrorHandler

All Known Implementing Classes:
  `LoggingCacheErrorHandler`, `SimpleCacheErrorHandler`

public interface CacheErrorHandler
A strategy for handling cache-related errors. In most cases, any exception thrown by the provider should simply be thrown back at the client but, in some circumstances, the infrastructure may need to handle cache-provider exceptions in a different way.

Typically, failing to retrieve an object from the cache with a given id can be transparently managed as a cache miss by not throwing back such exception.

Since:
  4.1
Author:
  Stephane Nicoll

## Method Summary

Modifier and Type
Method
Description
`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.

## Method Details

### handleCacheGetError

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.

Note that for a default `@Cacheable` setup, this will be called after an initial cache access failure, whereas the subsequent put step may independently fail and be handled in `handleCachePutError(java.lang.RuntimeException, org.springframework.cache.Cache, java.lang.Object, java.lang.Object)` still. However, for `@Cacheable(sync=true)`, there is only a combined get step with `handleCacheGetError` being called in case of failure; there won't be a separate put attempt after initial cache access failure anymore.

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)`
  - `Cache.get(Object, Callable)`

### handleCachePutError

void handleCachePutError(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 specified `key` and `value`, possibly rethrowing it as a fatal exception.

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

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.

Parameters:
  `exception` - the exception thrown by the cache provider
  `cache` - the cache
  `key` - the key used to clear the item

### handleCacheClearError

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.

Parameters:
  `exception` - the exception thrown by the cache provider
  `cache` - the cache to clear