org.springframework.cache.Cache adapter implementation
on top of a Caffeine com.github.benmanes.caffeine.cache.Cache instance.
Supports the retrieve(Object) and retrieve(Object, Supplier)
operations through Caffeine's AsyncCache, when provided via the
CaffeineCache(String, AsyncCache, boolean) constructor.
Requires Caffeine 3.0 or higher, as of Spring Framework 6.1.
CaffeineCacheManager
| Modifier and Type | Class and Description |
|---|---|
| private class | |
| private class |
| Modifier and Type | Field and Description |
|---|---|
| private AsyncCache | |
| private final Cache | |
| private final String |
| Access | Constructor and Description |
|---|---|
| public | CaffeineCache(String
the name of the cache name, Cache<Object, Object> the backing Caffeine Cache instance cache)Create a |
| public | CaffeineCache(String
the name of the cache name, Cache<Object, Object> the backing Caffeine Cache instance cache, boolean whether to accept and convert allowNullValues)null values
for this cacheCreate a |
| public | CaffeineCache(String
the name of the cache name, AsyncCache<Object, Object> the backing Caffeine AsyncCache instance cache, boolean whether to accept and convert allowNullValues)null values
for this cacheCreate a |
| Modifier and Type | Method and Description |
|---|---|
| public void | clear()
Implements org. Clear the cache through removing all mappings. |
| public void | evict(Object
the key whose mapping is to be removed from the cache key)Implements org. Evict the mapping for this key from this cache if it is present. |
| public boolean | evictIfPresent(Object
the key whose mapping is to be removed from the cache key)Overrides default org. Evict the mapping for this key from this cache if it is present, expecting the key to be immediately invisible for subsequent lookups. |
| public <T> T | get(Object
the key whose associated value is to be returned key, Callable<T> valueLoader)Implements org. Return the value to which this cache maps the specified key, obtaining
that value from |
| public final AsyncCache | |
| public final String | |
| public final Cache | getNativeCache()
Implements org. Return the internal Caffeine Cache
(possibly an adapter on top of an |
| public boolean | invalidate()
Overrides default org. Invalidate the cache through removing all mappings, expecting all entries to be immediately invisible for subsequent lookups. |
| protected Object | lookup(Object
the key whose associated value is to be returned key)Implements abstract org. Perform an actual lookup in the underlying store. |
| public void | put(Object
the key with which the specified value is to be associated key, Object the value to be associated with the specified key value)Implements org. Associate the specified value with the specified key in this cache. |
| public Cache. | putIfAbsent(Object
the key with which the specified value is to be associated key, Object the value to be associated with the specified key value)Overrides default org. Atomically associate the specified value with the specified key in this cache if it is not set already. |
| public CompletableFuture | retrieve(Object
the key whose associated value is to be returned key)Overrides default org. Return the value to which this cache maps the specified key,
wrapped in a |
| public <T> CompletableFuture | retrieve(Object
the key whose associated value is to be returned key, Supplier<CompletableFuture<T>> valueLoader)Overrides default org. Return the value to which this cache maps the specified key, obtaining
that value from |
| asyncCache | back to summary |
|---|---|
| private AsyncCache<Object, Object> asyncCache
| |
| cache | back to summary |
|---|---|
| private final Cache<Object, Object> cache | |
| name | back to summary |
|---|---|
| private final String name | |
| CaffeineCache | back to summary |
|---|---|
| public CaffeineCache(String name, Cache<Object, Object> cache) Create a | |
| CaffeineCache | back to summary |
|---|---|
| public CaffeineCache(String name, Cache<Object, Object> cache, boolean allowNullValues) Create a | |
| CaffeineCache | back to summary |
|---|---|
| public CaffeineCache(String name, AsyncCache<Object, Object> cache, boolean allowNullValues) Create a
| |
| clear | back to summary |
|---|---|
| public void clear() Implements org. Doc from org. Clear the cache through removing all mappings. Actual clearing may be performed in an asynchronous or deferred
fashion, with subsequent lookups possibly still seeing the entries.
This may for example be the case with transactional cache decorators.
Use If the cache is supposed to be compatible with
| |
| evict | back to summary |
|---|---|
| public void evict(Object key) Implements org. Doc from org. Evict the mapping for this key from this cache if it is present. Actual eviction may be performed in an asynchronous or deferred
fashion, with subsequent lookups possibly still seeing the entry.
This may for example be the case with transactional cache decorators.
Use If the cache is supposed to be compatible with | |
| evictIfPresent | back to summary |
|---|---|
| public boolean evictIfPresent(Object key) Overrides default org. Doc from org. Evict the mapping for this key from this cache if it is present, expecting the key to be immediately invisible for subsequent lookups. The default implementation delegates to | |
| get | back to summary |
|---|---|
| public <T> T get(Object key, Callable<T> valueLoader) Implements org. Doc from org. Return the value to which this cache maps the specified key, obtaining
that value from If possible, implementations should ensure that the loading operation
is synchronized so that the specified If the
| |
| getAsyncCache | back to summary |
|---|---|
| public final AsyncCache Return the internal Caffeine AsyncCache.
| |
| getName | back to summary |
|---|---|
| public final String getName() Implements org. Doc from org. Return the cache name.
| |
| getNativeCache | back to summary |
|---|---|
| public final Cache Implements org. Return the internal Caffeine Cache
(possibly an adapter on top of an
| |
| invalidate | back to summary |
|---|---|
| public boolean invalidate() Overrides default org. Doc from org. Invalidate the cache through removing all mappings, expecting all entries to be immediately invisible for subsequent lookups.
| |
| lookup | back to summary |
|---|---|
| protected Object lookup(Object key) Implements abstract org. Doc from org. Perform an actual lookup in the underlying store. | |
| put | back to summary |
|---|---|
| public void put(Object key, Object value) Implements org. Doc from org. Associate the specified value with the specified key in this cache. If the cache previously contained a mapping for this key, the old value is replaced by the specified value. Actual registration may be performed in an asynchronous or deferred
fashion, with subsequent lookups possibly not seeing the entry yet.
This may for example be the case with transactional cache decorators.
Use If the cache is supposed to be compatible with | |
| putIfAbsent | back to summary |
|---|---|
| public Cache. Overrides default org. Doc from org. Atomically associate the specified value with the specified key in this cache if it is not set already. This is equivalent to:
except that the action is performed atomically. While all out-of-the-box
CacheManager implementations are able to perform the put atomically,
the operation may also be implemented in two steps, e.g. with a check for
presence and a subsequent put, in a non-atomic way. Check the documentation
of the native cache implementation that you are using for more details.
The default implementation delegates to
| |
| retrieve | back to summary |
|---|---|
| public CompletableFuture Overrides default org. Doc from org. Return the value to which this cache maps the specified key,
wrapped in a Can return
| |
| retrieve | back to summary |
|---|---|
| public <T> CompletableFuture Overrides default org. Doc from org. Return the value to which this cache maps the specified key, obtaining
that value from If possible, implementations should ensure that the loading operation
is synchronized so that the specified Null values always indicate a user-level
| |
| Modifier and Type | Field and Description |
|---|---|
| private final Callable |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public Object | apply(Object
the function argument key)Implements java. Applies this function to the given argument. |
| valueLoader | back to summary |
|---|---|
| private final Callable<?> valueLoader | |
| LoadFunction | back to summary |
|---|---|
| public LoadFunction(Callable<?> valueLoader) | |
| apply | back to summary |
|---|---|
| public Object apply(Object key) Implements java. Doc from java. Applies this function to the given argument. | |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv boolean | |
| private final Object |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public Object | apply(Object
the function argument key)Implements java. Applies this function to the given argument. |
| called | back to summary |
|---|---|
| pack-priv boolean called | |
| value | back to summary |
|---|---|
| private final Object value
| |
| PutIfAbsentFunction | back to summary |
|---|---|
| public PutIfAbsentFunction(Object value) | |
| apply | back to summary |
|---|---|
| public Object apply(Object key) Implements java. Doc from java. Applies this function to the given argument. | |