org.infinispan.api
Interface BasicCache<K,V>

All Superinterfaces:
ConcurrentMap<K,V>, Lifecycle, Map<K,V>
All Known Subinterfaces:
AdvancedCache<K,V>, Cache<K,V>, RemoteCache<K,V>
All Known Implementing Classes:
AbstractDelegatingAdvancedCache, AbstractDelegatingCache, CacheImpl, CacheSupport, ClassLoaderSpecfiedCache, DecoratedCache, RemoteCacheImpl, RemoteCacheSupport

public interface BasicCache<K,V>
extends ConcurrentMap<K,V>, Lifecycle

BasicCache provides the common building block for the two different types of caches that Infinispan provides: embedded and remote.

For convenience, BasicCache extends ConcurrentMap and implements all methods accordingly, although methods like Map.keySet(), Map.values() and Map.entrySet() are expensive (prohibitively so when using a distributed cache) and frequent use of these methods is not recommended.

Other methods such as Map.size() provide an approximation-only, and should not be relied on for an accurate picture as to the size of the entire, distributed cache. Remote nodes are not queried and in-fly transactions are not taken into account, even if Map.size() is invoked from within such a transaction.

Also, like many ConcurrentMap implementations, BasicCache does not support the use of null keys or values.

Unsupported operations

Map.containsValue(Object)

Asynchronous operations

BasicCache also supports the use of "async" remote operations. Note that these methods only really make sense if you are using a clustered cache. I.e., when used in LOCAL mode, these "async" operations offer no benefit whatsoever. These methods, such as 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.

Please see the Infinispan documentation and/or the 5 Minute Usage Tutorial for more details.

Since:
4.0
Author:
Mircea.Markus@jboss.com, Manik Surtani, Galder ZamarreƱo
See Also:
CacheContainer, DefaultCacheManager, Infinispan documentation, 5 Minute Usage Tutorial

Nested Class Summary
 
Nested classes/interfaces inherited from interface java.util.Map
Map.Entry<K,V>
 
Method Summary
 NotifyingFuture<Void> clearAsync()
          Asynchronous version of Map.clear().
 NotifyingFuture<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.
 String getName()
          Retrieves the name of the cache
 String getVersion()
          Retrieves the version of Infinispan
 V put(K key, V value, long lifespan, TimeUnit unit)
          An overloaded form of Map.put(Object, Object), which takes in lifespan parameters.
 V put(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit)
          An overloaded form of Map.put(Object, Object), which takes in lifespan parameters.
 void putAll(Map<? extends K,? extends V> map, long lifespan, TimeUnit unit)
          An overloaded form of Map.putAll(Map), which takes in lifespan parameters.
 void putAll(Map<? extends K,? extends V> map, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit)
          An overloaded form of Map.putAll(Map), which takes in lifespan parameters.
 NotifyingFuture<Void> putAllAsync(Map<? extends K,? extends V> data)
          Asynchronous version of Map.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 Map.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).
 V putIfAbsent(K key, V value, long lifespan, TimeUnit unit)
          An overloaded form of ConcurrentMap.putIfAbsent(Object, Object), which takes in lifespan parameters.
 V putIfAbsent(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit)
          An overloaded form of ConcurrentMap.putIfAbsent(Object, Object), which takes in lifespan parameters.
 NotifyingFuture<V> putIfAbsentAsync(K key, V value)
          Asynchronous version of ConcurrentMap.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 Map.remove(Object).
 NotifyingFuture<Boolean> removeAsync(Object key, Object value)
          Asynchronous version of ConcurrentMap.remove(Object, Object).
 V replace(K key, V value, long lifespan, TimeUnit unit)
          An overloaded form of ConcurrentMap.replace(Object, Object), which takes in lifespan parameters.
 V replace(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit)
          An overloaded form of ConcurrentMap.replace(Object, Object), which takes in lifespan parameters.
 boolean replace(K key, V oldValue, V value, long lifespan, TimeUnit unit)
          An overloaded form of ConcurrentMap.replace(Object, Object, Object), which takes in lifespan parameters.
 boolean replace(K key, V oldValue, V value, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit)
          An overloaded form of ConcurrentMap.replace(Object, Object, Object), which takes in lifespan parameters.
 NotifyingFuture<V> replaceAsync(K key, V value)
          Asynchronous version of ConcurrentMap.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 ConcurrentMap.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).
 
Methods inherited from interface java.util.concurrent.ConcurrentMap
putIfAbsent, remove, replace, replace
 
Methods inherited from interface java.util.Map
clear, containsKey, containsValue, entrySet, equals, get, hashCode, isEmpty, keySet, put, putAll, remove, size, values
 
Methods inherited from interface org.infinispan.lifecycle.Lifecycle
start, stop
 

Method Detail

getName

String getName()
Retrieves the name of the cache

Returns:
the name of the cache

getVersion

String getVersion()
Retrieves the version of Infinispan

Returns:
a version string

put

V put(K key,
      V value,
      long lifespan,
      TimeUnit unit)
An overloaded form of Map.put(Object, Object), which takes in lifespan parameters.

Parameters:
key - key to use
value - value to store
lifespan - lifespan of the entry. Negative values are interpreted as unlimited lifespan.
unit - unit of measurement for the lifespan
Returns:
the value being replaced, or null if nothing is being replaced.

putIfAbsent

V putIfAbsent(K key,
              V value,
              long lifespan,
              TimeUnit unit)
An overloaded form of ConcurrentMap.putIfAbsent(Object, Object), which takes in lifespan parameters.

Parameters:
key - key to use
value - value to store
lifespan - lifespan of the entry. Negative values are interpreted as unlimited lifespan.
unit - unit of measurement for the lifespan
Returns:
the value being replaced, or null if nothing is being replaced.

putAll

void putAll(Map<? extends K,? extends V> map,
            long lifespan,
            TimeUnit unit)
An overloaded form of Map.putAll(Map), which takes in lifespan parameters. Note that the lifespan is applied to all mappings in the map passed in.

Parameters:
map - map containing mappings to enter
lifespan - lifespan of the entry. Negative values are interpreted as unlimited lifespan.
unit - unit of measurement for the lifespan

replace

V replace(K key,
          V value,
          long lifespan,
          TimeUnit unit)
An overloaded form of ConcurrentMap.replace(Object, Object), which takes in lifespan parameters.

Parameters:
key - key to use
value - value to store
lifespan - lifespan of the entry. Negative values are interpreted as unlimited lifespan.
unit - unit of measurement for the lifespan
Returns:
the value being replaced, or null if nothing is being replaced.

replace

boolean replace(K key,
                V oldValue,
                V value,
                long lifespan,
                TimeUnit unit)
An overloaded form of ConcurrentMap.replace(Object, Object, Object), which takes in lifespan parameters.

Parameters:
key - key to use
oldValue - value to replace
value - value to store
lifespan - lifespan of the entry. Negative values are interpreted as unlimited lifespan.
unit - unit of measurement for the lifespan
Returns:
true if the value was replaced, false otherwise

put

V put(K key,
      V value,
      long lifespan,
      TimeUnit lifespanUnit,
      long maxIdleTime,
      TimeUnit maxIdleTimeUnit)
An overloaded form of Map.put(Object, Object), which takes in lifespan parameters.

Parameters:
key - key to use
value - value to store
lifespan - lifespan of the entry. Negative values are interpreted as unlimited lifespan.
lifespanUnit - time unit for lifespan
maxIdleTime - the maximum amount of time this key is allowed to be idle for before it is considered as expired
maxIdleTimeUnit - time unit for max idle time
Returns:
the value being replaced, or null if nothing is being replaced.

putIfAbsent

V putIfAbsent(K key,
              V value,
              long lifespan,
              TimeUnit lifespanUnit,
              long maxIdleTime,
              TimeUnit maxIdleTimeUnit)
An overloaded form of ConcurrentMap.putIfAbsent(Object, Object), which takes in lifespan parameters.

Parameters:
key - key to use
value - value to store
lifespan - lifespan of the entry. Negative values are interpreted as unlimited lifespan.
lifespanUnit - time unit for lifespan
maxIdleTime - the maximum amount of time this key is allowed to be idle for before it is considered as expired
maxIdleTimeUnit - time unit for max idle time
Returns:
the value being replaced, or null if nothing is being replaced.

putAll

void putAll(Map<? extends K,? extends V> map,
            long lifespan,
            TimeUnit lifespanUnit,
            long maxIdleTime,
            TimeUnit maxIdleTimeUnit)
An overloaded form of Map.putAll(Map), which takes in lifespan parameters. Note that the lifespan is applied to all mappings in the map passed in.

Parameters:
map - map containing mappings to enter
lifespan - lifespan of the entry. Negative values are interpreted as unlimited lifespan.
lifespanUnit - time unit for lifespan
maxIdleTime - the maximum amount of time this key is allowed to be idle for before it is considered as expired
maxIdleTimeUnit - time unit for max idle time

replace

V replace(K key,
          V value,
          long lifespan,
          TimeUnit lifespanUnit,
          long maxIdleTime,
          TimeUnit maxIdleTimeUnit)
An overloaded form of ConcurrentMap.replace(Object, Object), which takes in lifespan parameters.

Parameters:
key - key to use
value - value to store
lifespan - lifespan of the entry. Negative values are interpreted as unlimited lifespan.
lifespanUnit - time unit for lifespan
maxIdleTime - the maximum amount of time this key is allowed to be idle for before it is considered as expired
maxIdleTimeUnit - time unit for max idle time
Returns:
the value being replaced, or null if nothing is being replaced.

replace

boolean replace(K key,
                V oldValue,
                V value,
                long lifespan,
                TimeUnit lifespanUnit,
                long maxIdleTime,
                TimeUnit maxIdleTimeUnit)
An overloaded form of ConcurrentMap.replace(Object, Object, Object), which takes in lifespan parameters.

Parameters:
key - key to use
oldValue - value to replace
value - value to store
lifespan - lifespan of the entry. Negative values are interpreted as unlimited lifespan.
lifespanUnit - time unit for lifespan
maxIdleTime - the maximum amount of time this key is allowed to be idle for before it is considered as expired
maxIdleTimeUnit - time unit for max idle time
Returns:
true if the value was replaced, false otherwise

putAsync

NotifyingFuture<V> putAsync(K key,
                            V value)
Asynchronous version of Map.put(Object, Object). This method does not block on remote calls, even if your cache mode is synchronous. Has no benefit over Map.put(Object, Object) if used in LOCAL mode.

Parameters:
key - key to use
value - value to store
Returns:
a future containing the old value replaced.

putAsync

NotifyingFuture<V> putAsync(K key,
                            V value,
                            long lifespan,
                            TimeUnit unit)
Asynchronous version of 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.

Parameters:
key - key to use
value - value to store
lifespan - lifespan of entry
unit - time unit for lifespan
Returns:
a future containing the old value replaced

putAsync

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). 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.

Parameters:
key - key to use
value - value to store
lifespan - lifespan of entry
lifespanUnit - time unit for lifespan
maxIdle - the maximum amount of time this key is allowed to be idle for before it is considered as expired
maxIdleUnit - time unit for max idle time
Returns:
a future containing the old value replaced

putAllAsync

NotifyingFuture<Void> putAllAsync(Map<? extends K,? extends V> data)
Asynchronous version of Map.putAll(Map). This method does not block on remote calls, even if your cache mode is synchronous. Has no benefit over Map.putAll(Map) if used in LOCAL mode.

Parameters:
data - to store
Returns:
a future containing a void return type

putAllAsync

NotifyingFuture<Void> putAllAsync(Map<? extends K,? extends V> data,
                                  long lifespan,
                                  TimeUnit unit)
Asynchronous version of 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.

Parameters:
data - to store
lifespan - lifespan of entry
unit - time unit for lifespan
Returns:
a future containing a void return type

putAllAsync

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). 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.

Parameters:
data - to store
lifespan - lifespan of entry
lifespanUnit - time unit for lifespan
maxIdle - the maximum amount of time this key is allowed to be idle for before it is considered as expired
maxIdleUnit - time unit for max idle time
Returns:
a future containing a void return type

clearAsync

NotifyingFuture<Void> clearAsync()
Asynchronous version of Map.clear(). This method does not block on remote calls, even if your cache mode is synchronous. Has no benefit over Map.clear() if used in LOCAL mode.

Returns:
a future containing a void return type

putIfAbsentAsync

NotifyingFuture<V> putIfAbsentAsync(K key,
                                    V value)
Asynchronous version of ConcurrentMap.putIfAbsent(Object, Object). This method does not block on remote calls, even if your cache mode is synchronous. Has no benefit over ConcurrentMap.putIfAbsent(Object, Object) if used in LOCAL mode.

Parameters:
key - key to use
value - value to store
Returns:
a future containing the old value replaced.

putIfAbsentAsync

NotifyingFuture<V> putIfAbsentAsync(K key,
                                    V value,
                                    long lifespan,
                                    TimeUnit unit)
Asynchronous version of 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.

Parameters:
key - key to use
value - value to store
lifespan - lifespan of entry
unit - time unit for lifespan
Returns:
a future containing the old value replaced

putIfAbsentAsync

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). 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.

Parameters:
key - key to use
value - value to store
lifespan - lifespan of entry
lifespanUnit - time unit for lifespan
maxIdle - the maximum amount of time this key is allowed to be idle for before it is considered as expired
maxIdleUnit - time unit for max idle time
Returns:
a future containing the old value replaced

removeAsync

NotifyingFuture<V> removeAsync(Object key)
Asynchronous version of Map.remove(Object). This method does not block on remote calls, even if your cache mode is synchronous. Has no benefit over Map.remove(Object) if used in LOCAL mode.

Parameters:
key - key to remove
Returns:
a future containing the value removed

removeAsync

NotifyingFuture<Boolean> removeAsync(Object key,
                                     Object value)
Asynchronous version of ConcurrentMap.remove(Object, Object). This method does not block on remote calls, even if your cache mode is synchronous. Has no benefit over ConcurrentMap.remove(Object, Object) if used in LOCAL mode.

Parameters:
key - key to remove
value - value to match on
Returns:
a future containing a boolean, indicating whether the entry was removed or not

replaceAsync

NotifyingFuture<V> replaceAsync(K key,
                                V value)
Asynchronous version of ConcurrentMap.replace(Object, Object). This method does not block on remote calls, even if your cache mode is synchronous. Has no benefit over ConcurrentMap.replace(Object, Object) if used in LOCAL mode.

Parameters:
key - key to remove
value - value to store
Returns:
a future containing the previous value overwritten

replaceAsync

NotifyingFuture<V> replaceAsync(K key,
                                V value,
                                long lifespan,
                                TimeUnit unit)
Asynchronous version of 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.

Parameters:
key - key to remove
value - value to store
lifespan - lifespan of entry
unit - time unit for lifespan
Returns:
a future containing the previous value overwritten

replaceAsync

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). 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.

Parameters:
key - key to remove
value - value to store
lifespan - lifespan of entry
lifespanUnit - time unit for lifespan
maxIdle - the maximum amount of time this key is allowed to be idle for before it is considered as expired
maxIdleUnit - time unit for max idle time
Returns:
a future containing the previous value overwritten

replaceAsync

NotifyingFuture<Boolean> replaceAsync(K key,
                                      V oldValue,
                                      V newValue)
Asynchronous version of ConcurrentMap.replace(Object, Object, Object). This method does not block on remote calls, even if your cache mode is synchronous. Has no benefit over ConcurrentMap.replace(Object, Object, Object) if used in LOCAL mode.

Parameters:
key - key to remove
oldValue - value to overwrite
newValue - value to store
Returns:
a future containing a boolean, indicating whether the entry was replaced or not

replaceAsync

NotifyingFuture<Boolean> replaceAsync(K key,
                                      V oldValue,
                                      V newValue,
                                      long lifespan,
                                      TimeUnit unit)
Asynchronous version of 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.

Parameters:
key - key to remove
oldValue - value to overwrite
newValue - value to store
lifespan - lifespan of entry
unit - time unit for lifespan
Returns:
a future containing a boolean, indicating whether the entry was replaced or not

replaceAsync

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). 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.

Parameters:
key - key to remove
oldValue - value to overwrite
newValue - value to store
lifespan - lifespan of entry
lifespanUnit - time unit for lifespan
maxIdle - the maximum amount of time this key is allowed to be idle for before it is considered as expired
maxIdleUnit - time unit for max idle time
Returns:
a future containing a boolean, indicating whether the entry was replaced or not

getAsync

NotifyingFuture<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. 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 cache loaders are configured, the get asynchronous call will act sequentially and will have no different to Map.get(Object).

Parameters:
key - key to retrieve
Returns:
a future that can be used to retrieve value associated with the key when this is available. The actual value returned by the future follows the same rules as Map.get(Object)

-->

Copyright © 2012 JBoss, a division of Red Hat. All Rights Reserved.