Package org.springframework.cache.interceptor

# Class AbstractCacheInvoker

java.lang.Object
org.springframework.cache.interceptor.AbstractCacheInvoker

Direct Known Subclasses:
  `CacheAspectSupport`

public abstract class AbstractCacheInvoker extends Object
A base component for invoking `Cache` operations and using a configurable `CacheErrorHandler` when an exception occurs.

Since:
  4.1
Author:
  Stephane Nicoll, Juergen Hoeller, Simon Baslé
See Also:
  - `CacheErrorHandler`

## Field Summary

Fields
Modifier and Type
Field
Description
`protected org.springframework.util.function.SingletonSupplier<CacheErrorHandler>`
`errorHandler`

## Constructor Summary

Constructors
Modifier
Constructor
Description
`protected`
`AbstractCacheInvoker()`
`protected`
`AbstractCacheInvoker(CacheErrorHandler errorHandler)`

## Method Summary

Modifier and Type
Method
Description
`protected void`
`doClear(Cache cache, boolean immediate)`
Execute `Cache.clear()` on the specified `Cache` and invoke the error handler if an exception occurs.
`protected void`
`doEvict(Cache cache, Object key, boolean immediate)`
Execute `Cache.evict(Object)`/`Cache.evictIfPresent(Object)` on the specified `Cache` and invoke the error handler if an exception occurs.
`protected Cache.ValueWrapper`
`doGet(Cache cache, Object key)`
Execute `Cache.get(Object)` on the specified `Cache` and invoke the error handler if an exception occurs.
`protected <T> T`
`doGet(Cache cache, Object key, Callable<T> valueLoader)`
Execute `Cache.get(Object, Callable)` on the specified `Cache` and invoke the error handler if an exception occurs.
`protected void`
`doPut(Cache cache, Object key, Object value)`
Execute `Cache.put(Object, Object)` on the specified `Cache` and invoke the error handler if an exception occurs.
`protected CompletableFuture<?>`
`doRetrieve(Cache cache, Object key)`
Execute `Cache.retrieve(Object)` on the specified `Cache` and invoke the error handler if an exception occurs.
`protected <T> CompletableFuture<T>`
`doRetrieve(Cache cache, Object key, Supplier<CompletableFuture<T>> valueLoader)`
Execute `Cache.retrieve(Object, Supplier)` on the specified `Cache` and invoke the error handler if an exception occurs.
`CacheErrorHandler`
`getErrorHandler()`
Return the `CacheErrorHandler` to use.
`void`
`setErrorHandler(CacheErrorHandler errorHandler)`
Set the `CacheErrorHandler` instance to use to handle errors thrown by the cache provider.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### errorHandler

protected org.springframework.util.function.SingletonSupplier<CacheErrorHandler> errorHandler

## Constructor Details

### AbstractCacheInvoker

protected AbstractCacheInvoker()

### AbstractCacheInvoker

protected AbstractCacheInvoker(CacheErrorHandler errorHandler)

## Method Details

### setErrorHandler

public void setErrorHandler(CacheErrorHandler errorHandler)
Set the `CacheErrorHandler` instance to use to handle errors thrown by the cache provider. By default, a `SimpleCacheErrorHandler` is used who throws any exception as is.

### getErrorHandler

public CacheErrorHandler getErrorHandler()
Return the `CacheErrorHandler` to use.

### doGet

@Nullable protected Cache.ValueWrapper doGet(Cache cache, Object key)
Execute `Cache.get(Object)` on the specified `Cache` and invoke the error handler if an exception occurs. Return `null` if the handler does not throw any exception, which simulates a cache miss in case of error.

See Also:
  - `Cache.get(Object)`

### doGet

@Nullable protected <T> T doGet(Cache cache, Object key, Callable<T> valueLoader)
Execute `Cache.get(Object, Callable)` on the specified `Cache` and invoke the error handler if an exception occurs. Invokes the `valueLoader` if the handler does not throw any exception, which simulates a cache read-through in case of error.

Since:
  6.2
See Also:
  - `Cache.get(Object, Callable)`

### doRetrieve

@Nullable protected CompletableFuture<?> doRetrieve(Cache cache, Object key)
Execute `Cache.retrieve(Object)` on the specified `Cache` and invoke the error handler if an exception occurs. Returns `null` if the handler does not throw any exception, which simulates a cache miss in case of error.

Since:
  6.2
See Also:
  - `Cache.retrieve(Object)`

### doRetrieve

protected <T> CompletableFuture<T> doRetrieve(Cache cache, Object key, Supplier<CompletableFuture<T>> valueLoader)
Execute `Cache.retrieve(Object, Supplier)` on the specified `Cache` and invoke the error handler if an exception occurs. Invokes the `valueLoader` if the handler does not throw any exception, which simulates a cache read-through in case of error.

Since:
  6.2
See Also:
  - `Cache.retrieve(Object, Supplier)`

### doPut

protected void doPut(Cache cache, Object key, @Nullable Object value)
Execute `Cache.put(Object, Object)` on the specified `Cache` and invoke the error handler if an exception occurs.

### doEvict

protected void doEvict(Cache cache, Object key, boolean immediate)
Execute `Cache.evict(Object)`/`Cache.evictIfPresent(Object)` on the specified `Cache` and invoke the error handler if an exception occurs.

### doClear

protected void doClear(Cache cache, boolean immediate)
Execute `Cache.clear()` on the specified `Cache` and invoke the error handler if an exception occurs.