org.springframework.cache.interceptor

## Class AbstractCacheInvoker

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

- Direct Known Subclasses:
    CacheAspectSupport, JCacheAspectSupport

      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
  See Also:
    `CacheErrorHandler`

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected SingletonSupplier<CacheErrorHandler>` | `errorHandler`

  - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `AbstractCacheInvoker()`
    `protected` | `AbstractCacheInvoker(CacheErrorHandler errorHandler)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and 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 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.
    `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 Detail

    - #### errorHandler

          protected SingletonSupplier<CacheErrorHandler> errorHandler

  - ### Constructor Detail

    - #### AbstractCacheInvoker

          protected AbstractCacheInvoker()

    - #### AbstractCacheInvoker

          protected AbstractCacheInvoker(CacheErrorHandler errorHandler)

  - ### Method Detail

    - #### 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)`

    - #### 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.