K - key typeV - value typepublic class CachingAsyncConsistentMap<K,V> extends DelegatingAsyncConsistentMap<K,V>
AsyncConsistentMap that caches entries on read.
The cache entries are automatically invalidated when updates are detected either locally or remotely.
This implementation only attempts to serve cached entries for get
calls. All other calls skip the cache and directly go the backing map.
DistributedPrimitive.Status, DistributedPrimitive.TypeDEFAULT_OPERTATION_TIMEOUT_MILLIS| Constructor and Description |
|---|
CachingAsyncConsistentMap(AsyncConsistentMap<K,V> backingMap)
Default constructor.
|
CachingAsyncConsistentMap(AsyncConsistentMap<K,V> backingMap,
int cacheSize)
Constructor to configure cache size.
|
| Modifier and Type | Method and Description |
|---|---|
CompletableFuture<Void> |
clear()
Removes all of the mappings from this map (optional operation).
|
CompletableFuture<Versioned<V>> |
computeIf(K key,
Predicate<? super V> condition,
BiFunction<? super K,? super V,? extends V> remappingFunction)
If the value for the specified key satisfies a condition, attempts to compute a new
mapping given the key and its current mapped value.
|
CompletableFuture<Void> |
destroy()
Purges state associated with this primitive.
|
CompletableFuture<Versioned<V>> |
get(K key)
Returns the value (and version) to which the specified key is mapped, or null if this
map contains no mapping for the key.
|
CompletableFuture<Versioned<V>> |
put(K key,
V value)
Associates the specified value with the specified key in this map (optional operation).
|
CompletableFuture<Versioned<V>> |
putAndGet(K key,
V value)
Associates the specified value with the specified key in this map (optional operation).
|
CompletableFuture<Versioned<V>> |
remove(K key)
Removes the mapping for a key from this map if it is present (optional operation).
|
CompletableFuture<Boolean> |
remove(K key,
long version)
Removes the entry for the specified key only if its current
version in the map is equal to the specified version.
|
CompletableFuture<Boolean> |
remove(K key,
V value)
Removes the entry for the specified key only if it is currently
mapped to the specified value.
|
CompletableFuture<Boolean> |
replace(K key,
long oldVersion,
V newValue)
Replaces the entry for the specified key only if it is currently mapped to the
specified version.
|
CompletableFuture<Versioned<V>> |
replace(K key,
V value)
Replaces the entry for the specified key only if there is any value
which associated with specified key.
|
CompletableFuture<Boolean> |
replace(K key,
V oldValue,
V newValue)
Replaces the entry for the specified key only if currently mapped
to the specified value.
|
addListener, addStatusChangeListener, begin, commit, containsKey, containsValue, entrySet, equals, getOrDefault, hashCode, keySet, prepare, prepareAndCommit, putIfAbsent, removeListener, removeStatusChangeListener, rollback, size, statusChangeListeners, toString, valuesapplicationId, name, primitiveTypeclone, finalize, getClass, notify, notifyAll, wait, wait, waitaddListener, asConsistentMap, asConsistentMap, compute, computeIfAbsent, computeIfPresent, isEmpty, primitiveTypeapplicationId, namepublic CachingAsyncConsistentMap(AsyncConsistentMap<K,V> backingMap)
backingMap - a distributed, strongly consistent map for backingpublic CachingAsyncConsistentMap(AsyncConsistentMap<K,V> backingMap, int cacheSize)
backingMap - a distributed, strongly consistent map for backingcacheSize - the maximum size of the cachepublic CompletableFuture<Void> destroy()
DistributedPrimitiveImplementations can override and provide appropriate clean up logic for purging any state state associated with the primitive. Whether modifications made within the destroy method have local or global visibility is left unspecified.
destroy in interface AsyncConsistentMap<K,V>destroy in interface DistributedPrimitivedestroy in class DelegatingDistributedPrimitiveCompletableFuture that is completed when the operation completespublic CompletableFuture<Versioned<V>> get(K key)
AsyncConsistentMapget in interface AsyncConsistentMap<K,V>get in class DelegatingAsyncConsistentMap<K,V>key - the key whose associated value (and version) is to be returnedpublic CompletableFuture<Versioned<V>> computeIf(K key, Predicate<? super V> condition, BiFunction<? super K,? super V,? extends V> remappingFunction)
AsyncConsistentMapcomputeIf in interface AsyncConsistentMap<K,V>computeIf in class DelegatingAsyncConsistentMap<K,V>key - key with which the specified value is to be associatedcondition - condition that should evaluate to true for the computation to proceedremappingFunction - the function to compute a valuepublic CompletableFuture<Versioned<V>> put(K key, V value)
AsyncConsistentMapput in interface AsyncConsistentMap<K,V>put in class DelegatingAsyncConsistentMap<K,V>key - key with which the specified value is to be associatedvalue - value to be associated with the specified keypublic CompletableFuture<Versioned<V>> putAndGet(K key, V value)
AsyncConsistentMapputAndGet in interface AsyncConsistentMap<K,V>putAndGet in class DelegatingAsyncConsistentMap<K,V>key - key with which the specified value is to be associatedvalue - value to be associated with the specified keypublic CompletableFuture<Versioned<V>> remove(K key)
AsyncConsistentMapremove in interface AsyncConsistentMap<K,V>remove in class DelegatingAsyncConsistentMap<K,V>key - key whose value is to be removed from the mappublic CompletableFuture<Void> clear()
AsyncConsistentMapclear in interface AsyncConsistentMap<K,V>clear in class DelegatingAsyncConsistentMap<K,V>public CompletableFuture<Boolean> remove(K key, V value)
AsyncConsistentMapremove in interface AsyncConsistentMap<K,V>remove in class DelegatingAsyncConsistentMap<K,V>key - key with which the specified value is associatedvalue - value expected to be associated with the specified keypublic CompletableFuture<Boolean> remove(K key, long version)
AsyncConsistentMapremove in interface AsyncConsistentMap<K,V>remove in class DelegatingAsyncConsistentMap<K,V>key - key with which the specified version is associatedversion - version expected to be associated with the specified keypublic CompletableFuture<Versioned<V>> replace(K key, V value)
AsyncConsistentMapreplace in interface AsyncConsistentMap<K,V>replace in class DelegatingAsyncConsistentMap<K,V>key - key with which the specified value is associatedvalue - value expected to be associated with the specified keypublic CompletableFuture<Boolean> replace(K key, V oldValue, V newValue)
AsyncConsistentMapreplace in interface AsyncConsistentMap<K,V>replace in class DelegatingAsyncConsistentMap<K,V>key - key with which the specified value is associatedoldValue - value expected to be associated with the specified keynewValue - value to be associated with the specified keypublic CompletableFuture<Boolean> replace(K key, long oldVersion, V newValue)
AsyncConsistentMapreplace in interface AsyncConsistentMap<K,V>replace in class DelegatingAsyncConsistentMap<K,V>key - key key with which the specified value is associatedoldVersion - version expected to be associated with the specified keynewValue - value to be associated with the specified key