Class CaffeineCache
java.lang.Object
org.springframework.cache.support.AbstractValueAdaptingCache
org.springframework.cache.caffeine.CaffeineCache
- All Implemented Interfaces:
org.springframework.cache.Cache
public class CaffeineCache
extends org.springframework.cache.support.AbstractValueAdaptingCache
Spring
Cache
adapter implementation
on top of a Caffeine 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.
- Since:
- 4.3
- Author:
- Ben Manes, Juergen Hoeller, Stephane Nicoll
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.springframework.cache.Cache
org.springframework.cache.Cache.ValueRetrievalException, org.springframework.cache.Cache.ValueWrapper
-
Constructor Summary
ConstructorDescriptionCaffeineCache
(String name, com.github.benmanes.caffeine.cache.AsyncCache<Object, Object> cache, boolean allowNullValues) Create aCaffeineCache
instance with the specified name and the given internalAsyncCache
to use.CaffeineCache
(String name, com.github.benmanes.caffeine.cache.Cache<Object, Object> cache) Create aCaffeineCache
instance with the specified name and the given internalCache
to use.CaffeineCache
(String name, com.github.benmanes.caffeine.cache.Cache<Object, Object> cache, boolean allowNullValues) Create aCaffeineCache
instance with the specified name and the given internalCache
to use. -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
void
boolean
evictIfPresent
(Object key) <T> T
Return the internal Caffeine AsyncCache.final String
getName()
Return the internal Caffeine Cache (possibly an adapter on top of angetAsyncCache()
).boolean
protected Object
void
org.springframework.cache.Cache.ValueWrapper
putIfAbsent
(Object key, Object value) <T> CompletableFuture<T>
retrieve
(Object key, Supplier<CompletableFuture<T>> valueLoader) Methods inherited from class org.springframework.cache.support.AbstractValueAdaptingCache
fromStoreValue, get, get, isAllowNullValues, toStoreValue, toValueWrapper
-
Constructor Details
-
CaffeineCache
Create aCaffeineCache
instance with the specified name and the given internalCache
to use.- Parameters:
name
- the name of the cachecache
- the backing Caffeine Cache instance
-
CaffeineCache
public CaffeineCache(String name, com.github.benmanes.caffeine.cache.Cache<Object, Object> cache, boolean allowNullValues) Create aCaffeineCache
instance with the specified name and the given internalCache
to use.- Parameters:
name
- the name of the cachecache
- the backing Caffeine Cache instanceallowNullValues
- whether to accept and convertnull
values for this cache
-
CaffeineCache
public CaffeineCache(String name, com.github.benmanes.caffeine.cache.AsyncCache<Object, Object> cache, boolean allowNullValues) Create aCaffeineCache
instance with the specified name and the given internalAsyncCache
to use.- Parameters:
name
- the name of the cachecache
- the backing Caffeine AsyncCache instanceallowNullValues
- whether to accept and convertnull
values for this cache- Since:
- 6.1
-
-
Method Details
-
getName
-
getNativeCache
Return the internal Caffeine Cache (possibly an adapter on top of angetAsyncCache()
). -
getAsyncCache
Return the internal Caffeine AsyncCache.- Throws:
IllegalStateException
- if no AsyncCache is available- Since:
- 6.1
- See Also:
-
get
-
retrieve
-
retrieve
-
lookup
- Specified by:
lookup
in classorg.springframework.cache.support.AbstractValueAdaptingCache
-
put
-
putIfAbsent
-
evict
-
evictIfPresent
-
clear
public void clear() -
invalidate
public boolean invalidate()
-