|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface Cache<K,V>
The central interface of Infinispan. A Cache provides a highly concurrent, optionally distributed data structure with additional features such as:
OutOfMemoryError
sCacheStore
, either when they are evicted as an overflow,
or all the time, to maintain persistent copies that would withstand server failure or restarts.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, Cache does not support the use of null keys or
values.
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.
CacheManager
.
CacheManager cm = new DefaultCacheManager(); // optionally pass in a default configuration Cache c = cm.getCache();See the
CacheManager
interface for more details on providing specific configurations, using multiple caches
in the same JVM, etc.
Please see the Infinispan documentation and/or the 5 Minute Usage Tutorial for more details.
CacheManager
,
DefaultCacheManager
,
Infinispan documentation,
5 Minute Usage TutorialNested 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() . |
void |
compact()
Method that releases object references of cached objects held in the cache by serializing them to byte buffers. |
void |
endBatch(boolean successful)
Completes a batch if one has been started using startBatch() . |
Set<Map.Entry<K,V>> |
entrySet()
Returns a set view of the mappings contained in this cache. |
void |
evict(K key)
Evicts an entry from the memory of the cache. |
AdvancedCache<K,V> |
getAdvancedCache()
|
CacheManager |
getCacheManager()
Retrieves the cache manager responsible for creating this cache instance. |
Configuration |
getConfiguration()
|
String |
getName()
Retrieves the name of the cache |
ComponentStatus |
getStatus()
|
String |
getVersion()
Retrieves the version of Infinispan |
Set<K> |
keySet()
Returns a set view of the keys contained in this cache. |
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) . |
void |
putForExternalRead(K key,
V value)
Under special operating behavior, associates the value with the specified key. |
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) . |
boolean |
startBatch()
Starts a batch. |
Collection<V> |
values()
Returns a collection view of the values contained in this cache. |
Methods inherited from interface java.util.concurrent.ConcurrentMap |
---|
putIfAbsent, remove, replace, replace |
Methods inherited from interface java.util.Map |
---|
clear, containsKey, containsValue, equals, get, hashCode, isEmpty, put, putAll, remove, size |
Methods inherited from interface org.infinispan.lifecycle.Lifecycle |
---|
start, stop |
Methods inherited from interface org.infinispan.notifications.Listenable |
---|
addListener, getListeners, removeListener |
Method Detail |
---|
void putForExternalRead(K key, V value)
ConcurrentMap.putIfAbsent(Object, Object)
)
key
- key with which the specified value is to be associated.value
- value to be associated with the specified key.
IllegalStateException
- if getStatus()
would not return ComponentStatus.RUNNING
.void evict(K key)
Map.remove(Object)
to remove an
entry from the entire cache system.
This method is designed to evict an entry from memory to free up memory used by the application. This method uses
a 0 lock acquisition timeout so it does not block in attempting to acquire locks. It behaves as a no-op if the
lock on the entry cannot be acquired immediately.
Important: this method should not be called from within a transaction scope.
key
- key to evictConfiguration getConfiguration()
boolean startBatch()
void endBatch(boolean successful)
startBatch()
. If no batch has been started, this is a
no-op.
successful
- if true, the batch completes, otherwise the batch is aborted and changes are not committed.String getName()
String getVersion()
CacheManager getCacheManager()
V put(K key, V value, long lifespan, TimeUnit unit)
Map.put(Object, Object)
, which takes in lifespan parameters.
key
- key to usevalue
- value to storelifespan
- lifespan of the entry. Negative values are interpreted as unlimited lifespan.unit
- unit of measurement for the lifespan
V putIfAbsent(K key, V value, long lifespan, TimeUnit unit)
ConcurrentMap.putIfAbsent(Object, Object)
, which takes in lifespan parameters.
key
- key to usevalue
- value to storelifespan
- lifespan of the entry. Negative values are interpreted as unlimited lifespan.unit
- unit of measurement for the lifespan
void putAll(Map<? extends K,? extends V> map, long lifespan, TimeUnit unit)
Map.putAll(Map)
, which takes in lifespan parameters. Note that the lifespan is applied
to all mappings in the map passed in.
map
- map containing mappings to enterlifespan
- lifespan of the entry. Negative values are interpreted as unlimited lifespan.unit
- unit of measurement for the lifespanV replace(K key, V value, long lifespan, TimeUnit unit)
ConcurrentMap.replace(Object, Object)
, which takes in lifespan parameters.
key
- key to usevalue
- value to storelifespan
- lifespan of the entry. Negative values are interpreted as unlimited lifespan.unit
- unit of measurement for the lifespan
boolean replace(K key, V oldValue, V value, long lifespan, TimeUnit unit)
ConcurrentMap.replace(Object, Object, Object)
, which takes in lifespan parameters.
key
- key to useoldValue
- value to replacevalue
- value to storelifespan
- lifespan of the entry. Negative values are interpreted as unlimited lifespan.unit
- unit of measurement for the lifespan
V put(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit)
Map.put(Object, Object)
, which takes in lifespan parameters.
key
- key to usevalue
- value to storelifespan
- lifespan of the entry. Negative values are interpreted as unlimited lifespan.lifespanUnit
- time unit for lifespanmaxIdleTime
- the maximum amount of time this key is allowed to be idle for before it is considered as
expiredmaxIdleTimeUnit
- time unit for max idle time
V putIfAbsent(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit)
ConcurrentMap.putIfAbsent(Object, Object)
, which takes in lifespan parameters.
key
- key to usevalue
- value to storelifespan
- lifespan of the entry. Negative values are interpreted as unlimited lifespan.lifespanUnit
- time unit for lifespanmaxIdleTime
- the maximum amount of time this key is allowed to be idle for before it is considered as
expiredmaxIdleTimeUnit
- time unit for max idle time
void putAll(Map<? extends K,? extends V> map, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit)
Map.putAll(Map)
, which takes in lifespan parameters. Note that the lifespan is applied
to all mappings in the map passed in.
map
- map containing mappings to enterlifespan
- lifespan of the entry. Negative values are interpreted as unlimited lifespan.lifespanUnit
- time unit for lifespanmaxIdleTime
- the maximum amount of time this key is allowed to be idle for before it is considered as
expiredmaxIdleTimeUnit
- time unit for max idle timeV replace(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit)
ConcurrentMap.replace(Object, Object)
, which takes in lifespan parameters.
key
- key to usevalue
- value to storelifespan
- lifespan of the entry. Negative values are interpreted as unlimited lifespan.lifespanUnit
- time unit for lifespanmaxIdleTime
- the maximum amount of time this key is allowed to be idle for before it is considered as
expiredmaxIdleTimeUnit
- time unit for max idle time
boolean replace(K key, V oldValue, V value, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit)
ConcurrentMap.replace(Object, Object, Object)
, which takes in lifespan parameters.
key
- key to useoldValue
- value to replacevalue
- value to storelifespan
- lifespan of the entry. Negative values are interpreted as unlimited lifespan.lifespanUnit
- time unit for lifespanmaxIdleTime
- the maximum amount of time this key is allowed to be idle for before it is considered as
expiredmaxIdleTimeUnit
- time unit for max idle time
NotifyingFuture<V> putAsync(K key, V value)
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.
key
- key to usevalue
- value to store
NotifyingFuture<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 lifespan
NotifyingFuture<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 time
NotifyingFuture<Void> putAllAsync(Map<? extends K,? extends V> data)
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.
data
- to store
NotifyingFuture<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 lifespan
NotifyingFuture<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 time
NotifyingFuture<Void> clearAsync()
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.
NotifyingFuture<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. Has no benefit over ConcurrentMap.putIfAbsent(Object, Object)
if used in LOCAL mode.
key
- key to usevalue
- value to store
NotifyingFuture<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 lifespan
NotifyingFuture<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 time
NotifyingFuture<V> removeAsync(Object key)
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.
key
- key to remove
NotifyingFuture<Boolean> removeAsync(Object key, Object value)
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.
key
- key to removevalue
- value to match on
NotifyingFuture<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. Has no benefit over ConcurrentMap.replace(Object, Object)
if used in LOCAL mode.
key
- key to removevalue
- value to store
NotifyingFuture<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 lifespan
NotifyingFuture<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 time
NotifyingFuture<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. Has no benefit over ConcurrentMap.replace(Object, Object, Object)
if used in
LOCAL mode.
key
- key to removeoldValue
- value to overwritenewValue
- value to store
NotifyingFuture<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 lifespan
NotifyingFuture<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 time
AdvancedCache<K,V> getAdvancedCache()
void compact()
ComponentStatus getStatus()
Set<K> keySet()
keySet
in interface Map<K,V>
Collection<V> values()
values
in interface Map<K,V>
Set<Map.Entry<K,V>> entrySet()
Map.Entry
. When this method is called on a cache configured with distribution mode, the set returned only
contains the mappings locally available in the cache instance. To avoid memory issues, there will be not attempt
to bring mappings from other nodes.
This method should only be used for debugging purposes such as to verify that the cache contains all the mappings
entered. Any other use involving execution of this method on a production system is not recommended.
entrySet
in interface Map<K,V>
|
Google Analytics | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |