Serves primarily as an SPI for Spring's annotation-based caching
model (org. and co)
and secondarily as an API for direct usage in applications.
Note
Due to the generic use of caching, it is recommended
that implementations allow storage of null values
(for example to cache methods that return null).
CacheManager, org.springframework.cache.annotation.Cacheable
| Modifier and Type | Class and Description |
|---|---|
| public static class | Cache.
Wrapper exception to be thrown from |
| public static interface | Cache.
A (wrapper) object representing a cache value. |
| Modifier and Type | Method and Description |
|---|---|
| public void | |
| public void | |
| public default boolean | Returns: true if the cache was known to have a mapping for
this key before, false if it did not (or if prior presence
could not be determined)the key whose mapping is to be removed from the cache key)Evict the mapping for this key from this cache if it is present, expecting the key to be immediately invisible for subsequent lookups. |
| public Cache. | Returns: the value to which this cache maps the specified key, contained within aValueWrapper which may also hold
a cached null value. A straight null being
returned means that the cache contains no mapping for this key.the key whose associated value is to be returned key)Return the value to which this cache maps the specified key. |
| public <T> T | Returns: the value to which this cache maps the specified key (which may benull itself), or also null if
the cache contains no mapping for this keythe key whose associated value is to be returned key, Class<T> the required type of the returned value (may be
type)null to bypass a type check; in case of a null
value found in the cache, the specified type is irrelevant)Return the value to which this cache maps the specified key, generically specifying a type that return value will be cast to. |
| public <T> T | |
| public String | |
| public Object | |
| public default boolean | Returns: true if the cache was known to have mappings before,
false if it did not (or if prior presence of entries could
not be determined)Invalidate the cache through removing all mappings, expecting all entries to be immediately invisible for subsequent lookups. |
| public void | |
| public default Cache. | Returns: the value to which this cache maps the specified key (which may benull itself), or also null if the cache did not contain any
mapping for that key prior to this call. Returning null is therefore
an indicator that the given value has been associated with the key.the key with which the specified value is to be associated key, Object the value to be associated with the specified key value)Atomically associate the specified value with the specified key in this cache if it is not set already. |
| public default CompletableFuture | Returns: the value to which this cache maps the specified key, contained within aCompletableFuture which may also be empty when a cache
miss has been late-determined. A straight null being returned
means that the cache immediately determined that it contains no mapping
for this key. A ValueWrapper contained within the
CompletableFuture indicates a cached value that is potentially
null; this is sensible in a late-determined scenario where a regular
CompletableFuture-contained null indicates a cache miss. However,
a cache may also return a plain value if it does not support the actual
caching of null values, avoiding the extra level of value wrapping.
Spring's cache processing can deal with all such implementation strategies.the key whose associated value is to be returned key)Return the value to which this cache maps the specified key,
wrapped in a |
| public default <T> CompletableFuture | Returns: the value to which this cache maps the specified key, contained within aCompletableFuture which will never be null.
The provided future is expected to produce a value or raise an exception.the key whose associated value is to be returned key, Supplier<CompletableFuture<T>> valueLoader)Return the value to which this cache maps the specified key, obtaining
that value from |
| clear | back to summary |
|---|---|
| public void clear() 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) 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 default boolean evictIfPresent(Object key) 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 Cache. Return the value to which this cache maps the specified key. Returns
| |
| get | back to summary |
|---|---|
| public <T> T get(Object key, Class<T> type) Return the value to which this cache maps the specified key, generically specifying a type that return value will be cast to. Note This variant of
| |
| get | back to summary |
|---|---|
| public <T> T get(Object key, Callable<T> valueLoader) 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 String getName() Return the cache name. | |
| getNativeCache | back to summary |
|---|---|
| public Object getNativeCache() Return the underlying native cache provider. | |
| invalidate | back to summary |
|---|---|
| public default boolean invalidate() Invalidate the cache through removing all mappings, expecting all entries to be immediately invisible for subsequent lookups.
| |
| put | back to summary |
|---|---|
| public void put(Object key, Object value) 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 default Cache. 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 default CompletableFuture Return the value to which this cache maps the specified key,
wrapped in a Can return
| |
| retrieve | back to summary |
|---|---|
| public default <T> CompletableFuture 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
| |
get(Object, Callable)
in case of the value loader callback failing with an exception.
| Access | Constructor and Description |
|---|---|
| public |
| key | back to summary |
|---|---|
| private final Object key
| |
| ValueRetrievalException | back to summary |
|---|---|
| public ValueRetrievalException(Object key, Callable<?> loader, Throwable ex) | |
| getKey | back to summary |
|---|---|
public Object getKey()
| |
| Modifier and Type | Method and Description |
|---|---|
| public Object |
| get | back to summary |
|---|---|
| public Object get() Return the actual value in the cache.
| |