K
- type parameter indicating the type of the cache keysV
- type parameter indicating the type of the data that is cached@PublicSpi public interface CacheMap<K,V>
CompletableFuture
<V>. A better name for this
class might have been FutureCache but that is history now.
The default implementation used by the data loader is based on a LinkedHashMap
.
This is really a cache of completed CompletableFuture
<V> values in memory. It is used, when caching is enabled, to
give back the same future to any code that may call it. If you need a cache of the underlying values that is possible external to the JVM
then you will want to use {ValueCache
} which is designed for external cache access.
Modifier and Type | Method and Description |
---|---|
CacheMap<K,V> |
clear()
Clears all entries of the cache map
|
boolean |
containsKey(K key)
Checks whether the specified key is contained in the cache map.
|
CacheMap<K,V> |
delete(K key)
Deletes the entry with the specified key from the cache map, if it exists.
|
java.util.concurrent.CompletableFuture<V> |
get(K key)
Gets the specified key from the cache map.
|
java.util.Collection<java.util.concurrent.CompletableFuture<V>> |
getAll()
Gets a collection of CompletableFutures from the cache map.
|
CacheMap<K,V> |
set(K key,
java.util.concurrent.CompletableFuture<V> value)
Creates a new cache map entry with the specified key and value, or updates the value if the key already exists.
|
static <K,V> CacheMap<K,V> |
simpleMap()
Creates a new cache map, using the default implementation that is based on a
LinkedHashMap . |
static <K,V> CacheMap<K,V> simpleMap()
LinkedHashMap
.K
- type parameter indicating the type of the cache keysV
- type parameter indicating the type of the data that is cachedboolean containsKey(K key)
key
- the key to checktrue
if the cache contains the key, false
otherwisejava.util.concurrent.CompletableFuture<V> get(K key)
May throw an exception if the key does not exists, depending on the cache map implementation that is used,
so be sure to check containsKey(Object)
first.
key
- the key to retrievenull
if not found (depends on cache implementation)java.util.Collection<java.util.concurrent.CompletableFuture<V>> getAll()
CacheMap<K,V> set(K key, java.util.concurrent.CompletableFuture<V> value)
key
- the key to cachevalue
- the value to cacheCacheMap<K,V> delete(K key)
key
- the key to delete