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.
- 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
ConstructorsConstructorDescriptionCaffeineCache(String name, com.github.benmanes.caffeine.cache.AsyncCache<Object, Object> cache, boolean allowNullValues) Create aCaffeineCacheinstance with the specified name and the given internalAsyncCacheto use.CaffeineCache(String name, com.github.benmanes.caffeine.cache.Cache<Object, Object> cache) Create aCaffeineCacheinstance with the specified name and the given internalCacheto use.CaffeineCache(String name, com.github.benmanes.caffeine.cache.Cache<Object, Object> cache, boolean allowNullValues) Create aCaffeineCacheinstance with the specified name and the given internalCacheto use. -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()voidbooleanevictIfPresent(Object key) <T> @Nullable TReturn the internal Caffeine AsyncCache.final StringgetName()Return the internal Caffeine Cache (possibly an adapter on top of angetAsyncCache()).booleanvoid@Nullable org.springframework.cache.Cache.ValueWrapperputIfAbsent(Object key, @Nullable 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 aCaffeineCacheinstance with the specified name and the given internalCacheto 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 aCaffeineCacheinstance with the specified name and the given internalCacheto use.- Parameters:
name- the name of the cachecache- the backing Caffeine Cache instanceallowNullValues- whether to accept and convertnullvalues for this cache
-
CaffeineCache
public CaffeineCache(String name, com.github.benmanes.caffeine.cache.AsyncCache<Object, Object> cache, boolean allowNullValues) Create aCaffeineCacheinstance with the specified name and the given internalAsyncCacheto use.- Parameters:
name- the name of the cachecache- the backing Caffeine AsyncCache instanceallowNullValues- whether to accept and convertnullvalues 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
-
put
-
putIfAbsent
-
evict
-
evictIfPresent
-
clear
public void clear() -
invalidate
public boolean invalidate()
-