org.springframework.cache.Cache implementation based on the core
JDK java.util.concurrent package.
Useful for testing or simple caching scenarios, typically in combination
with org. or
dynamically through ConcurrentMapCacheManager.
Supports the retrieve(Object) and retrieve(Object, Supplier)
operations in a best-effort fashion, relying on default CompletableFuture
execution (typically within the JVM's ForkJoinPool#commonPool()).
Note
As ConcurrentHashMap (the default implementation used)
does not allow for null values to be stored, this class will replace
them with a predefined internal object. This behavior can be changed through the
ConcurrentMapCache(String, ConcurrentMap, boolean) constructor.
ConcurrentMapCacheManager
| Modifier and Type | Field and Description |
|---|---|
| private final String | |
| private final SerializationDelegate | |
| private final ConcurrentMap |
| Access | Constructor and Description |
|---|---|
| public | ConcurrentMapCache(String
the name of the cache name)Create a new ConcurrentMapCache with the specified name. |
| public | ConcurrentMapCache(String
the name of the cache name, boolean whether to accept and convert allowNullValues)null
values for this cacheCreate a new ConcurrentMapCache with the specified name. |
| public | ConcurrentMapCache(String
the name of the cache name, ConcurrentMap<Object, Object> the ConcurrentMap to use as an internal store store, boolean whether to allow allowNullValues)null values
(adapting them to an internal null holder value)Create a new ConcurrentMapCache with the specified name and the
given internal |
| protected | ConcurrentMapCache(String
the name of the cache name, ConcurrentMap<Object, Object> the ConcurrentMap to use as an internal store store, boolean whether to allow allowNullValues, SerializationDelegate null values
(adapting them to an internal null holder value)the serialization)SerializationDelegate to use
to serialize cache entry or null to store the referenceCreate a new ConcurrentMapCache with the specified name and the
given internal |
| Modifier and Type | Method and Description |
|---|---|
| public void | clear()
Implements org. |
| public void | evict(Object
the key whose mapping is to be removed from the cache key)Implements org. |
| public boolean | evictIfPresent(Object
the key whose mapping is to be removed from the cache key)Overrides default org. |
| protected Object | fromStoreValue(Object
the store value storeValue)Overrides org. null).
|
| public <T> T | get(Object
the key whose associated value is to be returned key, Callable<T> valueLoader)Implements org. valueLoader if necessary.
|
| public final String | |
| public final ConcurrentMap | getNativeCache()
Implements org. |
| public boolean | invalidate()
Overrides default org. |
| public final boolean | isStoreByValue()
Return whether this cache stores a copy of each entry ( |
| protected Object | lookup(Object
the key whose associated value is to be returned key)Implements abstract org. |
| 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. |
| 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. |
| public CompletableFuture | retrieve(Object
the key whose associated value is to be returned key)Overrides default org. CompletableFuture.
|
| public <T> CompletableFuture | retrieve(Object
the key whose associated value is to be returned key, Supplier<CompletableFuture<T>> valueLoader)Overrides default org. valueLoader if necessary.
|
| protected Object | toStoreValue(Object
the given user value userValue)Overrides org. null).
|
| name | back to summary |
|---|---|
| private final String name | |
| serialization | back to summary |
|---|---|
| private final SerializationDelegate serialization
| |
| store | back to summary |
|---|---|
| private final ConcurrentMap<Object, Object> store | |
| ConcurrentMapCache | back to summary |
|---|---|
| public ConcurrentMapCache(String name) Create a new ConcurrentMapCache with the specified name.
| |
| ConcurrentMapCache | back to summary |
|---|---|
| public ConcurrentMapCache(String name, boolean allowNullValues) Create a new ConcurrentMapCache with the specified name.
| |
| ConcurrentMapCache | back to summary |
|---|---|
| public ConcurrentMapCache(String name, ConcurrentMap<Object, Object> store, boolean allowNullValues) Create a new ConcurrentMapCache with the specified name and the
given internal
| |
| ConcurrentMapCache | back to summary |
|---|---|
| protected ConcurrentMapCache(String name, ConcurrentMap<Object, Object> store, boolean allowNullValues, SerializationDelegate serialization) Create a new ConcurrentMapCache with the specified name and the
given internal
| |
| 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 | |
| fromStoreValue | back to summary |
|---|---|
| protected Object fromStoreValue(Object storeValue) Overrides org. Doc from org. Convert the given value from the internal store to a user value
returned from the get method (adapting | |
| 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
| |
| getName | back to summary |
|---|---|
| public final String getName() Implements org. Doc from org. Return the cache name.
| |
| getNativeCache | back to summary |
|---|---|
| public final ConcurrentMap Implements org. Doc from org. Return the underlying native cache provider.
| |
| 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.
| |
| isStoreByValue | back to summary |
|---|---|
| public final boolean isStoreByValue() Return whether this cache stores a copy of each entry (
| |
| 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
| |
| toStoreValue | back to summary |
|---|---|
| protected Object toStoreValue(Object userValue) Overrides org. Doc from org. Convert the given user value, as passed into the put method,
to a value in the internal store (adapting | |