public interface AsyncCache<K,V>
putAsync(Object, Object)
offer the best of both worlds between a fully synchronous and a fully asynchronous cache in that a
CompletableFuture is returned. The CompletableFuture can then be ignored or thrown away for typical
asynchronous behaviour, or queried for synchronous behaviour, which would block until any remote calls complete.
Note that all remote calls are, as far as the transport is concerned, synchronous. This allows you the guarantees
that remote calls succeed, while not blocking your application thread unnecessarily. For example, usage such as
the following could benefit from the async operations:
CompletableFuture f1 = cache.putAsync("key1", "value1");
CompletableFuture f2 = cache.putAsync("key2", "value2");
CompletableFuture f3 = cache.putAsync("key3", "value3");
f1.get();
f2.get();
f3.get();
The net result is behavior similar to synchronous RPC calls in that at the end, you have guarantees that all calls
completed successfully, but you have the added benefit that the three calls could happen in parallel. This is
especially advantageous if the cache uses distribution and the three keys map to different cache instances in the
cluster.
Also, the use of async operations when within a transaction return your local value only, as expected. A
CompletableFuture is still returned though for API consistency.
These methods can have benefit over their sync versions even in LOCAL mode.
| Modifier and Type | Method and Description |
|---|---|
java.util.concurrent.CompletableFuture<java.lang.Void> |
clearAsync()
Asynchronous version of
Map.clear(). |
java.util.concurrent.CompletableFuture<V> |
computeAsync(K key,
java.util.function.BiFunction<? super K,? super V,? extends V> remappingFunction)
Asynchronous version of
ConcurrentMap.compute(Object, BiFunction). |
java.util.concurrent.CompletableFuture<V> |
computeAsync(K key,
java.util.function.BiFunction<? super K,? super V,? extends V> remappingFunction,
long lifespan,
java.util.concurrent.TimeUnit lifespanUnit)
Asynchronous version of
BasicCache.compute(Object, BiFunction, long, TimeUnit). |
java.util.concurrent.CompletableFuture<V> |
computeAsync(K key,
java.util.function.BiFunction<? super K,? super V,? extends V> remappingFunction,
long lifespan,
java.util.concurrent.TimeUnit lifespanUnit,
long maxIdle,
java.util.concurrent.TimeUnit maxIdleUnit)
Asynchronous version of
BasicCache.compute(Object, BiFunction, long, TimeUnit, long, TimeUnit). |
java.util.concurrent.CompletableFuture<V> |
computeIfAbsentAsync(K key,
java.util.function.Function<? super K,? extends V> mappingFunction)
Asynchronous version of
ConcurrentMap.computeIfAbsent(Object, Function). |
java.util.concurrent.CompletableFuture<V> |
computeIfAbsentAsync(K key,
java.util.function.Function<? super K,? extends V> mappingFunction,
long lifespan,
java.util.concurrent.TimeUnit lifespanUnit)
Asynchronous version of
BasicCache.computeIfAbsent(Object, Function, long, TimeUnit). |
java.util.concurrent.CompletableFuture<V> |
computeIfAbsentAsync(K key,
java.util.function.Function<? super K,? extends V> mappingFunction,
long lifespan,
java.util.concurrent.TimeUnit lifespanUnit,
long maxIdle,
java.util.concurrent.TimeUnit maxIdleUnit)
Asynchronous version of
BasicCache.computeIfAbsent(Object, Function, long, TimeUnit, long, TimeUnit). |
java.util.concurrent.CompletableFuture<V> |
computeIfPresentAsync(K key,
java.util.function.BiFunction<? super K,? super V,? extends V> remappingFunction)
Asynchronous version of
ConcurrentMap.computeIfPresent(Object, BiFunction). |
java.util.concurrent.CompletableFuture<V> |
computeIfPresentAsync(K key,
java.util.function.BiFunction<? super K,? super V,? extends V> remappingFunction,
long lifespan,
java.util.concurrent.TimeUnit lifespanUnit)
Asynchronous version of
BasicCache.computeIfPresent(Object, BiFunction, long, TimeUnit) . |
java.util.concurrent.CompletableFuture<V> |
computeIfPresentAsync(K key,
java.util.function.BiFunction<? super K,? super V,? extends V> remappingFunction,
long lifespan,
java.util.concurrent.TimeUnit lifespanUnit,
long maxIdle,
java.util.concurrent.TimeUnit maxIdleUnit)
Asynchronous version of
BasicCache.computeIfPresent(Object, BiFunction, long, TimeUnit, long, TimeUnit) . |
default java.util.concurrent.CompletableFuture<java.lang.Boolean> |
containsKeyAsync(K key)
Asynchronous version of
Map.containsKey(Object) |
default java.util.concurrent.CompletableFuture<java.util.Map<K,V>> |
getAllAsync(java.util.Set<?> keys) |
java.util.concurrent.CompletableFuture<V> |
getAsync(K key)
Asynchronous version of
Map.get(Object) that allows user code to
retrieve the value associated with a key at a later stage, hence allowing
multiple parallel get requests to be sent. |
java.util.concurrent.CompletableFuture<V> |
mergeAsync(K key,
V value,
java.util.function.BiFunction<? super V,? super V,? extends V> remappingFunction)
Asynchronous version of
ConcurrentMap.merge(Object, Object, BiFunction). |
java.util.concurrent.CompletableFuture<V> |
mergeAsync(K key,
V value,
java.util.function.BiFunction<? super V,? super V,? extends V> remappingFunction,
long lifespan,
java.util.concurrent.TimeUnit lifespanUnit)
Asynchronous version of
BasicCache.merge(Object, Object, BiFunction, long, TimeUnit). |
java.util.concurrent.CompletableFuture<V> |
mergeAsync(K key,
V value,
java.util.function.BiFunction<? super V,? super V,? extends V> remappingFunction,
long lifespan,
java.util.concurrent.TimeUnit lifespanUnit,
long maxIdle,
java.util.concurrent.TimeUnit maxIdleUnit)
Asynchronous version of
BasicCache.merge(Object, Object, BiFunction, long, TimeUnit, long, TimeUnit). |
java.util.concurrent.CompletableFuture<java.lang.Void> |
putAllAsync(java.util.Map<? extends K,? extends V> data)
Asynchronous version of
Map.putAll(Map). |
java.util.concurrent.CompletableFuture<java.lang.Void> |
putAllAsync(java.util.Map<? extends K,? extends V> data,
long lifespan,
java.util.concurrent.TimeUnit unit)
Asynchronous version of
BasicCache.putAll(Map, long, TimeUnit). |
java.util.concurrent.CompletableFuture<java.lang.Void> |
putAllAsync(java.util.Map<? extends K,? extends V> data,
long lifespan,
java.util.concurrent.TimeUnit lifespanUnit,
long maxIdle,
java.util.concurrent.TimeUnit maxIdleUnit)
Asynchronous version of
BasicCache.putAll(Map, long, TimeUnit, long, TimeUnit). |
java.util.concurrent.CompletableFuture<V> |
putAsync(K key,
V value)
Asynchronous version of
BasicCache.put(Object, Object). |
java.util.concurrent.CompletableFuture<V> |
putAsync(K key,
V value,
long lifespan,
java.util.concurrent.TimeUnit unit)
Asynchronous version of
BasicCache.put(Object, Object, long, TimeUnit) . |
java.util.concurrent.CompletableFuture<V> |
putAsync(K key,
V value,
long lifespan,
java.util.concurrent.TimeUnit lifespanUnit,
long maxIdle,
java.util.concurrent.TimeUnit maxIdleUnit)
Asynchronous version of
BasicCache.put(Object, Object, long, TimeUnit, long, TimeUnit). |
java.util.concurrent.CompletableFuture<V> |
putIfAbsentAsync(K key,
V value)
Asynchronous version of
ConcurrentMap.putIfAbsent(Object, Object). |
java.util.concurrent.CompletableFuture<V> |
putIfAbsentAsync(K key,
V value,
long lifespan,
java.util.concurrent.TimeUnit unit)
Asynchronous version of
BasicCache.putIfAbsent(Object, Object, long, TimeUnit) . |
java.util.concurrent.CompletableFuture<V> |
putIfAbsentAsync(K key,
V value,
long lifespan,
java.util.concurrent.TimeUnit lifespanUnit,
long maxIdle,
java.util.concurrent.TimeUnit maxIdleUnit)
Asynchronous version of
BasicCache.putIfAbsent(Object, Object, long, TimeUnit, long, TimeUnit). |
java.util.concurrent.CompletableFuture<V> |
removeAsync(java.lang.Object key)
Asynchronous version of
BasicCache.remove(Object). |
java.util.concurrent.CompletableFuture<java.lang.Boolean> |
removeAsync(java.lang.Object key,
java.lang.Object value)
Asynchronous version of
ConcurrentMap.remove(Object, Object). |
java.util.concurrent.CompletableFuture<V> |
replaceAsync(K key,
V value)
Asynchronous version of
ConcurrentMap.replace(Object, Object). |
java.util.concurrent.CompletableFuture<V> |
replaceAsync(K key,
V value,
long lifespan,
java.util.concurrent.TimeUnit unit)
Asynchronous version of
BasicCache.replace(Object, Object, long, TimeUnit). |
java.util.concurrent.CompletableFuture<V> |
replaceAsync(K key,
V value,
long lifespan,
java.util.concurrent.TimeUnit lifespanUnit,
long maxIdle,
java.util.concurrent.TimeUnit maxIdleUnit)
Asynchronous version of
BasicCache.replace(Object, Object, long, TimeUnit, long, TimeUnit). |
java.util.concurrent.CompletableFuture<java.lang.Boolean> |
replaceAsync(K key,
V oldValue,
V newValue)
Asynchronous version of
ConcurrentMap.replace(Object, Object, Object). |
java.util.concurrent.CompletableFuture<java.lang.Boolean> |
replaceAsync(K key,
V oldValue,
V newValue,
long lifespan,
java.util.concurrent.TimeUnit unit)
Asynchronous version of
BasicCache.replace(Object, Object, Object, long, TimeUnit). |
java.util.concurrent.CompletableFuture<java.lang.Boolean> |
replaceAsync(K key,
V oldValue,
V newValue,
long lifespan,
java.util.concurrent.TimeUnit lifespanUnit,
long maxIdle,
java.util.concurrent.TimeUnit maxIdleUnit)
Asynchronous version of
BasicCache.replace(Object, Object, Object, long, TimeUnit, long, TimeUnit). |
java.util.concurrent.CompletableFuture<V> putAsync(K key, V value)
BasicCache.put(Object, Object). This method does not block on remote calls, even if your
cache mode is synchronous.key - key to usevalue - value to storejava.util.concurrent.CompletableFuture<V> putAsync(K key, V value, long lifespan, java.util.concurrent.TimeUnit unit)
BasicCache.put(Object, Object, long, TimeUnit) . This method does not block on remote
calls, even if your cache mode is synchronous.key - key to usevalue - value to storelifespan - lifespan of entryunit - time unit for lifespanjava.util.concurrent.CompletableFuture<V> putAsync(K key, V value, long lifespan, java.util.concurrent.TimeUnit lifespanUnit, long maxIdle, java.util.concurrent.TimeUnit maxIdleUnit)
BasicCache.put(Object, Object, long, TimeUnit, long, TimeUnit). This method does not block
on remote calls, even if your cache mode is synchronous.key - key to usevalue - value to storelifespan - lifespan of entrylifespanUnit - time unit for lifespanmaxIdle - the maximum amount of time this key is allowed to be idle for before it is considered as
expiredmaxIdleUnit - time unit for max idle timejava.util.concurrent.CompletableFuture<java.lang.Void> putAllAsync(java.util.Map<? extends K,? extends V> data)
Map.putAll(Map). This method does not block on remote calls, even if your cache mode
is synchronous.data - to storejava.util.concurrent.CompletableFuture<java.lang.Void> putAllAsync(java.util.Map<? extends K,? extends V> data, long lifespan, java.util.concurrent.TimeUnit unit)
BasicCache.putAll(Map, long, TimeUnit). This method does not block on remote calls, even if
your cache mode is synchronous.data - to storelifespan - lifespan of entryunit - time unit for lifespanjava.util.concurrent.CompletableFuture<java.lang.Void> putAllAsync(java.util.Map<? extends K,? extends V> data, long lifespan, java.util.concurrent.TimeUnit lifespanUnit, long maxIdle, java.util.concurrent.TimeUnit maxIdleUnit)
BasicCache.putAll(Map, long, TimeUnit, long, TimeUnit). This method does not block on
remote calls, even if your cache mode is synchronous.data - to storelifespan - lifespan of entrylifespanUnit - time unit for lifespanmaxIdle - the maximum amount of time this key is allowed to be idle for before it is considered as
expiredmaxIdleUnit - time unit for max idle timejava.util.concurrent.CompletableFuture<java.lang.Void> clearAsync()
Map.clear(). This method does not block on remote calls, even if your cache mode is
synchronous.java.util.concurrent.CompletableFuture<V> putIfAbsentAsync(K key, V value)
ConcurrentMap.putIfAbsent(Object, Object). This method does not block on remote calls, even if
your cache mode is synchronous.key - key to usevalue - value to storejava.util.concurrent.CompletableFuture<V> putIfAbsentAsync(K key, V value, long lifespan, java.util.concurrent.TimeUnit unit)
BasicCache.putIfAbsent(Object, Object, long, TimeUnit) . This method does not block on
remote calls, even if your cache mode is synchronous.key - key to usevalue - value to storelifespan - lifespan of entryunit - time unit for lifespanjava.util.concurrent.CompletableFuture<V> putIfAbsentAsync(K key, V value, long lifespan, java.util.concurrent.TimeUnit lifespanUnit, long maxIdle, java.util.concurrent.TimeUnit maxIdleUnit)
BasicCache.putIfAbsent(Object, Object, long, TimeUnit, long, TimeUnit). This method does
not block on remote calls, even if your cache mode is synchronous.key - key to usevalue - value to storelifespan - lifespan of entrylifespanUnit - time unit for lifespanmaxIdle - the maximum amount of time this key is allowed to be idle for before it is considered as
expiredmaxIdleUnit - time unit for max idle timejava.util.concurrent.CompletableFuture<V> removeAsync(java.lang.Object key)
BasicCache.remove(Object). This method does not block on remote calls, even if your cache
mode is synchronous.key - key to removejava.util.concurrent.CompletableFuture<java.lang.Boolean> removeAsync(java.lang.Object key,
java.lang.Object value)
ConcurrentMap.remove(Object, Object). This method does not block on remote calls, even if your
cache mode is synchronous.key - key to removevalue - value to match onjava.util.concurrent.CompletableFuture<V> replaceAsync(K key, V value)
ConcurrentMap.replace(Object, Object). This method does not block on remote calls, even if
your cache mode is synchronous.key - key to removevalue - value to storejava.util.concurrent.CompletableFuture<V> replaceAsync(K key, V value, long lifespan, java.util.concurrent.TimeUnit unit)
BasicCache.replace(Object, Object, long, TimeUnit). This method does not block on remote
calls, even if your cache mode is synchronous.key - key to removevalue - value to storelifespan - lifespan of entryunit - time unit for lifespanjava.util.concurrent.CompletableFuture<V> replaceAsync(K key, V value, long lifespan, java.util.concurrent.TimeUnit lifespanUnit, long maxIdle, java.util.concurrent.TimeUnit maxIdleUnit)
BasicCache.replace(Object, Object, long, TimeUnit, long, TimeUnit). This method does not
block on remote calls, even if your cache mode is synchronous.key - key to removevalue - value to storelifespan - lifespan of entrylifespanUnit - time unit for lifespanmaxIdle - the maximum amount of time this key is allowed to be idle for before it is considered as
expiredmaxIdleUnit - time unit for max idle timejava.util.concurrent.CompletableFuture<java.lang.Boolean> replaceAsync(K key, V oldValue, V newValue)
ConcurrentMap.replace(Object, Object, Object). This method does not block on remote calls,
even if your cache mode is synchronous.key - key to removeoldValue - value to overwritenewValue - value to storejava.util.concurrent.CompletableFuture<java.lang.Boolean> replaceAsync(K key, V oldValue, V newValue, long lifespan, java.util.concurrent.TimeUnit unit)
BasicCache.replace(Object, Object, Object, long, TimeUnit). This method does not block on
remote calls, even if your cache mode is synchronous.key - key to removeoldValue - value to overwritenewValue - value to storelifespan - lifespan of entryunit - time unit for lifespanjava.util.concurrent.CompletableFuture<java.lang.Boolean> replaceAsync(K key, V oldValue, V newValue, long lifespan, java.util.concurrent.TimeUnit lifespanUnit, long maxIdle, java.util.concurrent.TimeUnit maxIdleUnit)
BasicCache.replace(Object, Object, Object, long, TimeUnit, long, TimeUnit). This method
does not block on remote calls, even if your cache mode is synchronous.key - key to removeoldValue - value to overwritenewValue - value to storelifespan - lifespan of entrylifespanUnit - time unit for lifespanmaxIdle - the maximum amount of time this key is allowed to be idle for before it is considered as
expiredmaxIdleUnit - time unit for max idle timejava.util.concurrent.CompletableFuture<V> getAsync(K key)
Map.get(Object) that allows user code to
retrieve the value associated with a key at a later stage, hence allowing
multiple parallel get requests to be sent. Normally, when this method
detects that the value is likely to be retrieved from from a remote
entity, it will span a different thread in order to allow the
asynchronous get call to return immediately. If the call will definitely
resolve locally, for example when the cache is configured with LOCAL mode
and no stores are configured, the get asynchronous call will act
sequentially and will have no different to Map.get(Object).key - key to retrieveMap.get(Object)default java.util.concurrent.CompletableFuture<java.lang.Boolean> containsKeyAsync(K key)
Map.containsKey(Object)key - key to retrievedefault java.util.concurrent.CompletableFuture<java.util.Map<K,V>> getAllAsync(java.util.Set<?> keys)
java.util.concurrent.CompletableFuture<V> computeAsync(K key, java.util.function.BiFunction<? super K,? super V,? extends V> remappingFunction)
ConcurrentMap.compute(Object, BiFunction). This method does not block on remote
calls, even if your cache mode is synchronous.java.util.concurrent.CompletableFuture<V> computeAsync(K key, java.util.function.BiFunction<? super K,? super V,? extends V> remappingFunction, long lifespan, java.util.concurrent.TimeUnit lifespanUnit)
BasicCache.compute(Object, BiFunction, long, TimeUnit). This method does not block on remote
calls, even if your cache mode is synchronous.java.util.concurrent.CompletableFuture<V> computeAsync(K key, java.util.function.BiFunction<? super K,? super V,? extends V> remappingFunction, long lifespan, java.util.concurrent.TimeUnit lifespanUnit, long maxIdle, java.util.concurrent.TimeUnit maxIdleUnit)
BasicCache.compute(Object, BiFunction, long, TimeUnit, long, TimeUnit). This method does not block on remote
calls, even if your cache mode is synchronous.java.util.concurrent.CompletableFuture<V> computeIfAbsentAsync(K key, java.util.function.Function<? super K,? extends V> mappingFunction)
ConcurrentMap.computeIfAbsent(Object, Function). This method does not block on remote
calls, even if your cache mode is synchronous.java.util.concurrent.CompletableFuture<V> computeIfAbsentAsync(K key, java.util.function.Function<? super K,? extends V> mappingFunction, long lifespan, java.util.concurrent.TimeUnit lifespanUnit)
BasicCache.computeIfAbsent(Object, Function, long, TimeUnit). This method does not block on remote
calls, even if your cache mode is synchronous.java.util.concurrent.CompletableFuture<V> computeIfAbsentAsync(K key, java.util.function.Function<? super K,? extends V> mappingFunction, long lifespan, java.util.concurrent.TimeUnit lifespanUnit, long maxIdle, java.util.concurrent.TimeUnit maxIdleUnit)
BasicCache.computeIfAbsent(Object, Function, long, TimeUnit, long, TimeUnit). This method does not block on remote
calls, even if your cache mode is synchronous.java.util.concurrent.CompletableFuture<V> computeIfPresentAsync(K key, java.util.function.BiFunction<? super K,? super V,? extends V> remappingFunction)
ConcurrentMap.computeIfPresent(Object, BiFunction). This method does not block on
remote calls, even if your cache mode is synchronous.java.util.concurrent.CompletableFuture<V> computeIfPresentAsync(K key, java.util.function.BiFunction<? super K,? super V,? extends V> remappingFunction, long lifespan, java.util.concurrent.TimeUnit lifespanUnit)
BasicCache.computeIfPresent(Object, BiFunction, long, TimeUnit) . This method does not block on
remote calls, even if your cache mode is synchronous.java.util.concurrent.CompletableFuture<V> computeIfPresentAsync(K key, java.util.function.BiFunction<? super K,? super V,? extends V> remappingFunction, long lifespan, java.util.concurrent.TimeUnit lifespanUnit, long maxIdle, java.util.concurrent.TimeUnit maxIdleUnit)
BasicCache.computeIfPresent(Object, BiFunction, long, TimeUnit, long, TimeUnit) . This method does not block on
remote calls, even if your cache mode is synchronous.java.util.concurrent.CompletableFuture<V> mergeAsync(K key, V value, java.util.function.BiFunction<? super V,? super V,? extends V> remappingFunction)
ConcurrentMap.merge(Object, Object, BiFunction). This method does not block on remote
calls, even if your cache mode is synchronous.java.util.concurrent.CompletableFuture<V> mergeAsync(K key, V value, java.util.function.BiFunction<? super V,? super V,? extends V> remappingFunction, long lifespan, java.util.concurrent.TimeUnit lifespanUnit)
BasicCache.merge(Object, Object, BiFunction, long, TimeUnit). This method does not
block on remote calls, even if your cache mode is synchronous.java.util.concurrent.CompletableFuture<V> mergeAsync(K key, V value, java.util.function.BiFunction<? super V,? super V,? extends V> remappingFunction, long lifespan, java.util.concurrent.TimeUnit lifespanUnit, long maxIdle, java.util.concurrent.TimeUnit maxIdleUnit)
BasicCache.merge(Object, Object, BiFunction, long, TimeUnit, long, TimeUnit). This
method does not block on remote calls, even if your cache mode is synchronous.