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
NotifyingFuture
is returned. The NotifyingFuture 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:
NotifyingFuture f1 = cache.putAsync("key1", "value1"); NotifyingFuture f2 = cache.putAsync("key2", "value2"); NotifyingFuture 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 NotifyingFuture is still returned though for API consistency.
Modifier and Type | Method and Description |
---|---|
NotifyingFuture<Void> |
clearAsync()
Asynchronous version of
#clear() . |
NotifyingFuture<V> |
getAsync(K key)
Asynchronous version of
#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. |
NotifyingFuture<Void> |
putAllAsync(Map<? extends K,? extends V> data)
Asynchronous version of
#putAll(Map) . |
NotifyingFuture<Void> |
putAllAsync(Map<? extends K,? extends V> data,
long lifespan,
TimeUnit unit)
Asynchronous version of
#putAll(Map, long, TimeUnit) . |
NotifyingFuture<Void> |
putAllAsync(Map<? extends K,? extends V> data,
long lifespan,
TimeUnit lifespanUnit,
long maxIdle,
TimeUnit maxIdleUnit)
Asynchronous version of
#putAll(Map, long, TimeUnit, long, TimeUnit) . |
NotifyingFuture<V> |
putAsync(K key,
V value)
Asynchronous version of
#put(Object, Object) . |
NotifyingFuture<V> |
putAsync(K key,
V value,
long lifespan,
TimeUnit unit)
Asynchronous version of
#put(Object, Object, long, TimeUnit) . |
NotifyingFuture<V> |
putAsync(K key,
V value,
long lifespan,
TimeUnit lifespanUnit,
long maxIdle,
TimeUnit maxIdleUnit)
Asynchronous version of
#put(Object, Object, long, TimeUnit, long, TimeUnit) . |
NotifyingFuture<V> |
putIfAbsentAsync(K key,
V value)
Asynchronous version of
#putIfAbsent(Object, Object) . |
NotifyingFuture<V> |
putIfAbsentAsync(K key,
V value,
long lifespan,
TimeUnit unit)
Asynchronous version of
#putIfAbsent(Object, Object, long, TimeUnit) . |
NotifyingFuture<V> |
putIfAbsentAsync(K key,
V value,
long lifespan,
TimeUnit lifespanUnit,
long maxIdle,
TimeUnit maxIdleUnit)
Asynchronous version of
#putIfAbsent(Object, Object, long, TimeUnit, long, TimeUnit) . |
NotifyingFuture<V> |
removeAsync(Object key)
Asynchronous version of
#remove(Object) . |
NotifyingFuture<Boolean> |
removeAsync(Object key,
Object value)
Asynchronous version of
#remove(Object, Object) . |
NotifyingFuture<V> |
replaceAsync(K key,
V value)
Asynchronous version of
#replace(Object, Object) . |
NotifyingFuture<V> |
replaceAsync(K key,
V value,
long lifespan,
TimeUnit unit)
Asynchronous version of
#replace(Object, Object, long, TimeUnit) . |
NotifyingFuture<V> |
replaceAsync(K key,
V value,
long lifespan,
TimeUnit lifespanUnit,
long maxIdle,
TimeUnit maxIdleUnit)
Asynchronous version of
#replace(Object, Object, long, TimeUnit, long, TimeUnit) . |
NotifyingFuture<Boolean> |
replaceAsync(K key,
V oldValue,
V newValue)
Asynchronous version of
#replace(Object, Object, Object) . |
NotifyingFuture<Boolean> |
replaceAsync(K key,
V oldValue,
V newValue,
long lifespan,
TimeUnit unit)
Asynchronous version of
#replace(Object, Object, Object, long, TimeUnit) . |
NotifyingFuture<Boolean> |
replaceAsync(K key,
V oldValue,
V newValue,
long lifespan,
TimeUnit lifespanUnit,
long maxIdle,
TimeUnit maxIdleUnit)
Asynchronous version of
#replace(Object, Object, Object, long, TimeUnit, long, TimeUnit) . |
NotifyingFuture<V> putAsync(K key, V value)
#put(Object, Object)
. This method does not block on remote calls, even if your
cache mode is synchronous. Has no benefit over #put(Object, Object)
if used in LOCAL mode.
key
- key to usevalue
- value to storeNotifyingFuture<V> putAsync(K key, V value, long lifespan, TimeUnit unit)
#put(Object, Object, long, TimeUnit)
. This method does not block on remote
calls, even if your cache mode is synchronous. Has no benefit over #put(Object, Object, long, TimeUnit)
if used in LOCAL mode.key
- key to usevalue
- value to storelifespan
- lifespan of entryunit
- time unit for lifespanNotifyingFuture<V> putAsync(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit)
#put(Object, Object, long, TimeUnit, long, TimeUnit)
. This method does not block
on remote calls, even if your cache mode is synchronous. Has no benefit over #put(Object, Object, long,
TimeUnit, long, TimeUnit)
if used in LOCAL mode.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 timeNotifyingFuture<Void> putAllAsync(Map<? extends K,? extends V> data)
#putAll(Map)
. This method does not block on remote calls, even if your cache mode
is synchronous. Has no benefit over #putAll(Map)
if used in LOCAL mode.data
- to storeNotifyingFuture<Void> putAllAsync(Map<? extends K,? extends V> data, long lifespan, TimeUnit unit)
#putAll(Map, long, TimeUnit)
. This method does not block on remote calls, even if
your cache mode is synchronous. Has no benefit over #putAll(Map, long, TimeUnit)
if used in LOCAL mode.data
- to storelifespan
- lifespan of entryunit
- time unit for lifespanNotifyingFuture<Void> putAllAsync(Map<? extends K,? extends V> data, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit)
#putAll(Map, long, TimeUnit, long, TimeUnit)
. This method does not block on
remote calls, even if your cache mode is synchronous. Has no benefit over #putAll(Map, long, TimeUnit,
long, TimeUnit)
if used in LOCAL mode.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 timeNotifyingFuture<Void> clearAsync()
#clear()
. This method does not block on remote calls, even if your cache mode is
synchronous. Has no benefit over #clear()
if used in LOCAL mode.NotifyingFuture<V> putIfAbsentAsync(K key, V value)
#putIfAbsent(Object, Object)
. This method does not block on remote calls, even if
your cache mode is synchronous. Has no benefit over #putIfAbsent(Object, Object)
if used in LOCAL mode.
key
- key to usevalue
- value to storeNotifyingFuture<V> putIfAbsentAsync(K key, V value, long lifespan, TimeUnit unit)
#putIfAbsent(Object, Object, long, TimeUnit)
. This method does not block on
remote calls, even if your cache mode is synchronous. Has no benefit over #putIfAbsent(Object, Object,
long, TimeUnit)
if used in LOCAL mode.key
- key to usevalue
- value to storelifespan
- lifespan of entryunit
- time unit for lifespanNotifyingFuture<V> putIfAbsentAsync(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit)
#putIfAbsent(Object, Object, long, TimeUnit, long, TimeUnit)
. This method does
not block on remote calls, even if your cache mode is synchronous. Has no benefit over #putIfAbsent(Object, Object, long, TimeUnit, long, TimeUnit)
if used in LOCAL mode.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 timeNotifyingFuture<V> removeAsync(Object key)
#remove(Object)
. This method does not block on remote calls, even if your cache
mode is synchronous. Has no benefit over #remove(Object)
if used in LOCAL mode.key
- key to removeNotifyingFuture<Boolean> removeAsync(Object key, Object value)
#remove(Object, Object)
. This method does not block on remote calls, even if your
cache mode is synchronous. Has no benefit over #remove(Object, Object)
if used in LOCAL mode.key
- key to removevalue
- value to match onNotifyingFuture<V> replaceAsync(K key, V value)
#replace(Object, Object)
. This method does not block on remote calls, even if
your cache mode is synchronous. Has no benefit over #replace(Object, Object)
if used in LOCAL mode.key
- key to removevalue
- value to storeNotifyingFuture<V> replaceAsync(K key, V value, long lifespan, TimeUnit unit)
#replace(Object, Object, long, TimeUnit)
. This method does not block on remote
calls, even if your cache mode is synchronous. Has no benefit over #replace(Object, Object, long,
TimeUnit)
if used in LOCAL mode.key
- key to removevalue
- value to storelifespan
- lifespan of entryunit
- time unit for lifespanNotifyingFuture<V> replaceAsync(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit)
#replace(Object, Object, long, TimeUnit, long, TimeUnit)
. This method does not
block on remote calls, even if your cache mode is synchronous. Has no benefit over #replace(Object,
Object, long, TimeUnit, long, TimeUnit)
if used in LOCAL mode.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 timeNotifyingFuture<Boolean> replaceAsync(K key, V oldValue, V newValue)
#replace(Object, Object, Object)
. This method does not block on remote calls,
even if your cache mode is synchronous. Has no benefit over #replace(Object, Object, Object)
if used in
LOCAL mode.key
- key to removeoldValue
- value to overwritenewValue
- value to storeNotifyingFuture<Boolean> replaceAsync(K key, V oldValue, V newValue, long lifespan, TimeUnit unit)
#replace(Object, Object, Object, long, TimeUnit)
. This method does not block on
remote calls, even if your cache mode is synchronous. Has no benefit over #replace(Object, Object, Object,
long, TimeUnit)
if used in LOCAL mode.key
- key to removeoldValue
- value to overwritenewValue
- value to storelifespan
- lifespan of entryunit
- time unit for lifespanNotifyingFuture<Boolean> replaceAsync(K key, V oldValue, V newValue, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit)
#replace(Object, Object, Object, long, TimeUnit, long, TimeUnit)
. This method
does not block on remote calls, even if your cache mode is synchronous. Has no benefit over #replace(Object, Object, Object, long, TimeUnit, long, TimeUnit)
if used in LOCAL mode.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 timeNotifyingFuture<V> getAsync(K key)
#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 #get(Object)
.key
- key to retrieve#get(Object)
Copyright © 2014 JBoss, a division of Red Hat. All Rights Reserved.