public class DecoratedCache<K,V> extends AbstractDelegatingAdvancedCache<K,V>
ClassLoader
and a set of Flag
s. This
ClassLoader
and set of Flag
s will be applied to all cache invocations made via this decorator.
In addition to cleaner and more readable code, this approach offers a performance benefit to using AdvancedCache.with(ClassLoader)
or AdvancedCache.withFlags(org.infinispan.context.Flag...)
APIs, thanks to
internal optimizations that can be made when the ClassLoader
and Flag
set is unchanging.AdvancedCache.with(ClassLoader)
,
AdvancedCache.withFlags(org.infinispan.context.Flag...)
AbstractDelegatingAdvancedCache.AdvancedCacheWrapper<K,V>
cache
Constructor and Description |
---|
DecoratedCache(AdvancedCache<K,V> delegate,
ClassLoader classLoader) |
DecoratedCache(AdvancedCache<K,V> delegate,
ClassLoader classLoader,
Flag... flags) |
DecoratedCache(AdvancedCache<K,V> delegate,
Flag... flags) |
Modifier and Type | Method and Description |
---|---|
void |
addListener(Object listener)
Adds a listener to the component.
|
void |
addListener(Object listener,
KeyFilter<? super K> filter)
Adds a listener to the component.
|
CacheSet<CacheEntry<K,V>> |
cacheEntrySet()
Identical to
Cache.entrySet() but is typed to return CacheEntries instead of Entries. |
void |
clear()
Removes all mappings from the cache.
|
org.infinispan.commons.util.concurrent.NotifyingFuture<Void> |
clearAsync() |
boolean |
containsKey(Object key) |
boolean |
containsValue(Object value) |
CacheSet<Map.Entry<K,V>> |
entrySet()
Returns a set view of the mappings contained in this cache and cache loader across the entire cluster.
|
void |
evict(K key)
Evicts an entry from the memory of the cache.
|
EntryIterable<K,V> |
filterEntries(KeyValueFilter<? super K,? super V> filter)
Retrieve the entry iterable that can be used to iterate over the contents of this cache.
|
V |
get(Object key) |
Map<K,V> |
getAll(Set<?> keys)
Gets a collection of entries, returning them as
Map of the values
associated with the set of keys requested. |
org.infinispan.commons.util.concurrent.NotifyingFuture<V> |
getAsync(K key) |
CacheEntry |
getCacheEntry(Object key)
Retrieves a CacheEntry corresponding to a specific key.
|
ClassLoader |
getClassLoader()
Returns the cache loader associated associated with this cache.
|
EnumSet<Flag> |
getFlags() |
Map<K,V> |
getGroup(String groupName)
It fetches all the keys which belong to the group.
|
boolean |
isEmpty() |
CacheSet<K> |
keySet()
Returns a set view of the keys contained in this cache and cache loader across the entire cluster.
|
boolean |
lock(Collection<? extends K> keys)
Locks collections of keys eagerly across cache nodes in a cluster.
|
boolean |
lock(K... keys)
Locks a given key or keys eagerly across cache nodes in a cluster.
|
V |
put(K key,
V value) |
V |
put(K key,
V value,
long lifespan,
TimeUnit unit) |
V |
put(K key,
V value,
long lifespan,
TimeUnit lifespanUnit,
long maxIdleTime,
TimeUnit maxIdleTimeUnit) |
V |
put(K key,
V value,
Metadata metadata)
An overloaded form of
#put(K, V) , which takes in an instance of
Metadata which can be used to provide metadata information for
the entry being stored, such as lifespan, version of value...etc. |
void |
putAll(Map<? extends K,? extends V> m) |
void |
putAll(Map<? extends K,? extends V> map,
long lifespan,
TimeUnit unit) |
void |
putAll(Map<? extends K,? extends V> map,
long lifespan,
TimeUnit lifespanUnit,
long maxIdleTime,
TimeUnit maxIdleTimeUnit) |
void |
putAll(Map<? extends K,? extends V> map,
Metadata metadata)
An overloaded form of
Map.putAll(Map) , which takes in an instance of
Metadata which can be used to provide metadata information for
the entries being stored, such as lifespan, version of value...etc. |
org.infinispan.commons.util.concurrent.NotifyingFuture<Void> |
putAllAsync(Map<? extends K,? extends V> data) |
org.infinispan.commons.util.concurrent.NotifyingFuture<Void> |
putAllAsync(Map<? extends K,? extends V> data,
long lifespan,
TimeUnit unit) |
org.infinispan.commons.util.concurrent.NotifyingFuture<Void> |
putAllAsync(Map<? extends K,? extends V> data,
long lifespan,
TimeUnit lifespanUnit,
long maxIdle,
TimeUnit maxIdleUnit) |
org.infinispan.commons.util.concurrent.NotifyingFuture<V> |
putAsync(K key,
V value) |
org.infinispan.commons.util.concurrent.NotifyingFuture<V> |
putAsync(K key,
V value,
long lifespan,
TimeUnit unit) |
org.infinispan.commons.util.concurrent.NotifyingFuture<V> |
putAsync(K key,
V value,
long lifespan,
TimeUnit lifespanUnit,
long maxIdle,
TimeUnit maxIdleUnit) |
org.infinispan.commons.util.concurrent.NotifyingFuture<V> |
putAsync(K key,
V value,
Metadata metadata)
Asynchronous version of
AdvancedCache.put(Object, Object, Metadata) which stores
metadata alongside the value. |
void |
putForExternalRead(K key,
V value)
Under special operating behavior, associates the value with the specified key.
|
void |
putForExternalRead(K key,
V value,
long lifespan,
TimeUnit unit)
An overloaded form of
#putForExternalRead(K, V) , which takes in lifespan parameters. |
void |
putForExternalRead(K key,
V value,
long lifespan,
TimeUnit lifespanUnit,
long maxIdle,
TimeUnit maxIdleUnit)
An overloaded form of
#putForExternalRead(K, V) , which takes in lifespan parameters. |
void |
putForExternalRead(K key,
V value,
Metadata metadata)
An overloaded form of
#putForExternalRead(K, V) , which takes in an
instance of Metadata which can be used to provide metadata
information for the entry being stored, such as lifespan, version
of value...etc. |
V |
putIfAbsent(K key,
V value) |
V |
putIfAbsent(K key,
V value,
long lifespan,
TimeUnit unit) |
V |
putIfAbsent(K key,
V value,
long lifespan,
TimeUnit lifespanUnit,
long maxIdleTime,
TimeUnit maxIdleTimeUnit) |
V |
putIfAbsent(K key,
V value,
Metadata metadata)
An overloaded form of
#putIfAbsent(K, V) , which takes in an
instance of Metadata which can be used to provide metadata
information for the entry being stored, such as lifespan, version
of value...etc. |
org.infinispan.commons.util.concurrent.NotifyingFuture<V> |
putIfAbsentAsync(K key,
V value) |
org.infinispan.commons.util.concurrent.NotifyingFuture<V> |
putIfAbsentAsync(K key,
V value,
long lifespan,
TimeUnit unit) |
org.infinispan.commons.util.concurrent.NotifyingFuture<V> |
putIfAbsentAsync(K key,
V value,
long lifespan,
TimeUnit lifespanUnit,
long maxIdle,
TimeUnit maxIdleUnit) |
V |
remove(Object key) |
boolean |
remove(Object key,
Object value) |
org.infinispan.commons.util.concurrent.NotifyingFuture<V> |
removeAsync(Object key) |
org.infinispan.commons.util.concurrent.NotifyingFuture<Boolean> |
removeAsync(Object key,
Object value) |
void |
removeGroup(String groupName)
It removes all the key which belongs to a group.
|
V |
replace(K key,
V value) |
V |
replace(K key,
V value,
long lifespan,
TimeUnit unit) |
V |
replace(K key,
V value,
long lifespan,
TimeUnit lifespanUnit,
long maxIdleTime,
TimeUnit maxIdleTimeUnit) |
V |
replace(K key,
V value,
Metadata metadata)
An overloaded form of
#replace(K, V) , which takes in an
instance of Metadata which can be used to provide metadata
information for the entry being stored, such as lifespan, version
of value...etc. |
boolean |
replace(K key,
V oldValue,
V newValue) |
boolean |
replace(K key,
V oldValue,
V value,
long lifespan,
TimeUnit unit) |
boolean |
replace(K key,
V oldValue,
V value,
long lifespan,
TimeUnit lifespanUnit,
long maxIdleTime,
TimeUnit maxIdleTimeUnit) |
boolean |
replace(K key,
V oldValue,
V value,
Metadata metadata)
An overloaded form of
#replace(K, V, V) , which takes in an
instance of Metadata which can be used to provide metadata
information for the entry being stored, such as lifespan, version
of value...etc. |
org.infinispan.commons.util.concurrent.NotifyingFuture<V> |
replaceAsync(K key,
V value) |
org.infinispan.commons.util.concurrent.NotifyingFuture<V> |
replaceAsync(K key,
V value,
long lifespan,
TimeUnit unit) |
org.infinispan.commons.util.concurrent.NotifyingFuture<V> |
replaceAsync(K key,
V value,
long lifespan,
TimeUnit lifespanUnit,
long maxIdle,
TimeUnit maxIdleUnit) |
org.infinispan.commons.util.concurrent.NotifyingFuture<Boolean> |
replaceAsync(K key,
V oldValue,
V newValue) |
org.infinispan.commons.util.concurrent.NotifyingFuture<Boolean> |
replaceAsync(K key,
V oldValue,
V newValue,
long lifespan,
TimeUnit unit) |
org.infinispan.commons.util.concurrent.NotifyingFuture<Boolean> |
replaceAsync(K key,
V oldValue,
V newValue,
long lifespan,
TimeUnit lifespanUnit,
long maxIdle,
TimeUnit maxIdleUnit) |
int |
size()
Returns a count of all elements in this cache and cache loader across the entire cluster.
|
void |
stop() |
CacheCollection<V> |
values()
Returns a collection view of the values contained in this cache across the entire cluster.
|
AdvancedCache<K,V> |
with(ClassLoader classLoader)
Using this operation, users can call any
AdvancedCache operation
with a given ClassLoader . |
AdvancedCache<K,V> |
withFlags(Flag... flags)
A method that adds flags to any API call.
|
addInterceptor, addInterceptorAfter, addInterceptorBefore, applyDelta, getAdvancedCache, getAllCacheEntries, getAuthorizationManager, getAvailability, getBatchContainer, getComponentRegistry, getDataContainer, getDistributionManager, getEvictionManager, getExpirationManager, getInterceptorChain, getInvocationContextContainer, getLockManager, getRpcManager, getStats, getTransactionManager, getXAResource, putForExternalRead, putForExternalRead, removeExpired, removeInterceptor, removeInterceptor, setAvailability
addFilteredListener, addListener, endBatch, getCacheConfiguration, getCacheManager, getDelegate, getListeners, getName, getStatus, getVersion, removeListener, set, start, startBatch, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
getCacheConfiguration, getCacheManager, getStatus
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, replaceAll
addFilteredListener, addListener
getListeners, removeListener
public DecoratedCache(AdvancedCache<K,V> delegate, ClassLoader classLoader)
public DecoratedCache(AdvancedCache<K,V> delegate, Flag... flags)
public DecoratedCache(AdvancedCache<K,V> delegate, ClassLoader classLoader, Flag... flags)
public AdvancedCache<K,V> with(ClassLoader classLoader)
AdvancedCache
AdvancedCache
operation
with a given ClassLoader
. This means that any ClassLoader
happening
as a result of the cache operation will be done using the ClassLoader
given. For example:
When users store POJO instances in caches configured with StoreAsBinaryConfiguration
,
these instances are transformed into byte arrays. When these entries are
read from the cache, a lazy unmarshalling process happens where these byte
arrays are transformed back into POJO instances. Using AdvancedCache.with(ClassLoader)
when reading that enables users to provide the class loader that should
be used when trying to locate the classes that are constructed as a result
of the unmarshalling process.
cache.with(classLoader).get(key);Note that for the flag to take effect, the cache operation must be invoked on the instance returned by this method. As an alternative to setting this on every invocation, users could also consider using the
DecoratedCache
wrapper, as this allows for more readable
code. E.g.:
Cache classLoaderSpecificCache = new DecoratedCache(cache, classLoader); classLoaderSpecificCache.get(key1); classLoaderSpecificCache.get(key2); classLoaderSpecificCache.get(key3);
with
in interface AdvancedCache<K,V>
with
in class AbstractDelegatingAdvancedCache<K,V>
AdvancedCache
instance upon which operations can be called
with a particular ClassLoader
.public AdvancedCache<K,V> withFlags(Flag... flags)
AdvancedCache
cache.withFlags(Flag.FORCE_WRITE_LOCK).get(key);will invoke a cache.get() with a write lock forced. Note that for the flag to take effect, the cache operation must be invoked on the instance returned by this method. As an alternative to setting this on every invocation, users could also consider using the
DecoratedCache
wrapper, as this allows for more readable
code. E.g.:
Cache forceWriteLockCache = new DecoratedCache(cache, Flag.FORCE_WRITE_LOCK); forceWriteLockCache.get(key1); forceWriteLockCache.get(key2); forceWriteLockCache.get(key3);
withFlags
in interface AdvancedCache<K,V>
withFlags
in class AbstractDelegatingAdvancedCache<K,V>
flags
- a set of flags to apply. See the Flag
documentation.AdvancedCache
instance on which a real operation is to be invoked, if the flags are
to be applied.public ClassLoader getClassLoader()
AdvancedCache
DecoratedCache
wrapper.getClassLoader
in interface AdvancedCache<K,V>
getClassLoader
in class AbstractDelegatingAdvancedCache<K,V>
public void stop()
stop
in interface org.infinispan.commons.api.Lifecycle
stop
in class AbstractDelegatingCache<K,V>
public boolean lock(K... keys)
AdvancedCache
Keys can be locked eagerly in the context of a transaction only.
lock
in interface AdvancedCache<K,V>
lock
in class AbstractDelegatingAdvancedCache<K,V>
keys
- the keys to lockFlag.FAIL_SILENTLY
.public boolean lock(Collection<? extends K> keys)
AdvancedCache
Collections of keys can be locked eagerly in the context of a transaction only.
lock
in interface AdvancedCache<K,V>
lock
in class AbstractDelegatingAdvancedCache<K,V>
keys
- collection of keys to lockFlag.FAIL_SILENTLY
.public void putForExternalRead(K key, V value)
Cache
ConcurrentMap.putIfAbsent(Object, Object)
)
putForExternalRead
in interface Cache<K,V>
putForExternalRead
in class AbstractDelegatingCache<K,V>
key
- key with which the specified value is to be associated.value
- value to be associated with the specified key.public void putForExternalRead(K key, V value, Metadata metadata)
AdvancedCache
#putForExternalRead(K, V)
, which takes in an
instance of Metadata
which can be used to provide metadata
information for the entry being stored, such as lifespan, version
of value...etc. The Metadata
is only stored if the call is
successful.putForExternalRead
in interface AdvancedCache<K,V>
putForExternalRead
in class AbstractDelegatingAdvancedCache<K,V>
key
- key with which the specified value is to be associatedvalue
- value to be associated with the specified keymetadata
- information to store alongside the new valuepublic void putForExternalRead(K key, V value, long lifespan, TimeUnit unit)
Cache
#putForExternalRead(K, V)
, which takes in lifespan parameters.putForExternalRead
in interface Cache<K,V>
putForExternalRead
in class AbstractDelegatingCache<K,V>
key
- key to usevalue
- value to storelifespan
- lifespan of the entry. Negative values are interpreted as unlimited lifespan.unit
- unit of measurement for the lifespanpublic void putForExternalRead(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit)
Cache
#putForExternalRead(K, V)
, which takes in lifespan parameters.putForExternalRead
in interface Cache<K,V>
putForExternalRead
in class AbstractDelegatingCache<K,V>
key
- key to usevalue
- value to storelifespan
- lifespan of the entry. Negative values are interpreted as unlimited lifespan.lifespanUnit
- 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 timepublic void evict(K key)
Cache
BasicCache.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.public V putIfAbsent(K key, V value, long lifespan, TimeUnit unit)
putIfAbsent
in interface org.infinispan.commons.api.BasicCache<K,V>
putIfAbsent
in class AbstractDelegatingCache<K,V>
public V put(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit)
public V putIfAbsent(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit)
putIfAbsent
in interface org.infinispan.commons.api.BasicCache<K,V>
putIfAbsent
in class AbstractDelegatingCache<K,V>
public void putAll(Map<? extends K,? extends V> map, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit)
public V replace(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit)
public boolean replace(K key, V oldValue, V value, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit)
public org.infinispan.commons.util.concurrent.NotifyingFuture<V> putAsync(K key, V value, long lifespan, TimeUnit unit)
public org.infinispan.commons.util.concurrent.NotifyingFuture<V> putAsync(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit)
public org.infinispan.commons.util.concurrent.NotifyingFuture<Void> putAllAsync(Map<? extends K,? extends V> data)
putAllAsync
in interface org.infinispan.commons.api.AsyncCache<K,V>
putAllAsync
in class AbstractDelegatingCache<K,V>
public org.infinispan.commons.util.concurrent.NotifyingFuture<Void> putAllAsync(Map<? extends K,? extends V> data, long lifespan, TimeUnit unit)
putAllAsync
in interface org.infinispan.commons.api.AsyncCache<K,V>
putAllAsync
in class AbstractDelegatingCache<K,V>
public org.infinispan.commons.util.concurrent.NotifyingFuture<Void> putAllAsync(Map<? extends K,? extends V> data, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit)
putAllAsync
in interface org.infinispan.commons.api.AsyncCache<K,V>
putAllAsync
in class AbstractDelegatingCache<K,V>
public org.infinispan.commons.util.concurrent.NotifyingFuture<Void> clearAsync()
clearAsync
in interface org.infinispan.commons.api.AsyncCache<K,V>
clearAsync
in class AbstractDelegatingCache<K,V>
public org.infinispan.commons.util.concurrent.NotifyingFuture<V> putIfAbsentAsync(K key, V value)
putIfAbsentAsync
in interface org.infinispan.commons.api.AsyncCache<K,V>
putIfAbsentAsync
in class AbstractDelegatingCache<K,V>
public org.infinispan.commons.util.concurrent.NotifyingFuture<V> putIfAbsentAsync(K key, V value, long lifespan, TimeUnit unit)
putIfAbsentAsync
in interface org.infinispan.commons.api.AsyncCache<K,V>
putIfAbsentAsync
in class AbstractDelegatingCache<K,V>
public org.infinispan.commons.util.concurrent.NotifyingFuture<V> putIfAbsentAsync(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit)
putIfAbsentAsync
in interface org.infinispan.commons.api.AsyncCache<K,V>
putIfAbsentAsync
in class AbstractDelegatingCache<K,V>
public org.infinispan.commons.util.concurrent.NotifyingFuture<V> removeAsync(Object key)
removeAsync
in interface org.infinispan.commons.api.AsyncCache<K,V>
removeAsync
in class AbstractDelegatingCache<K,V>
public org.infinispan.commons.util.concurrent.NotifyingFuture<Boolean> removeAsync(Object key, Object value)
removeAsync
in interface org.infinispan.commons.api.AsyncCache<K,V>
removeAsync
in class AbstractDelegatingCache<K,V>
public org.infinispan.commons.util.concurrent.NotifyingFuture<V> replaceAsync(K key, V value)
replaceAsync
in interface org.infinispan.commons.api.AsyncCache<K,V>
replaceAsync
in class AbstractDelegatingCache<K,V>
public org.infinispan.commons.util.concurrent.NotifyingFuture<V> replaceAsync(K key, V value, long lifespan, TimeUnit unit)
replaceAsync
in interface org.infinispan.commons.api.AsyncCache<K,V>
replaceAsync
in class AbstractDelegatingCache<K,V>
public org.infinispan.commons.util.concurrent.NotifyingFuture<V> replaceAsync(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit)
replaceAsync
in interface org.infinispan.commons.api.AsyncCache<K,V>
replaceAsync
in class AbstractDelegatingCache<K,V>
public org.infinispan.commons.util.concurrent.NotifyingFuture<Boolean> replaceAsync(K key, V oldValue, V newValue)
replaceAsync
in interface org.infinispan.commons.api.AsyncCache<K,V>
replaceAsync
in class AbstractDelegatingCache<K,V>
public org.infinispan.commons.util.concurrent.NotifyingFuture<Boolean> replaceAsync(K key, V oldValue, V newValue, long lifespan, TimeUnit unit)
replaceAsync
in interface org.infinispan.commons.api.AsyncCache<K,V>
replaceAsync
in class AbstractDelegatingCache<K,V>
public org.infinispan.commons.util.concurrent.NotifyingFuture<Boolean> replaceAsync(K key, V oldValue, V newValue, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit)
replaceAsync
in interface org.infinispan.commons.api.AsyncCache<K,V>
replaceAsync
in class AbstractDelegatingCache<K,V>
public int size()
Cache
Flag.SKIP_CACHE_LOAD
flag should be used to
avoid hitting the cache loader in case if this is not needed in the size calculation.
Also if you want the local contents only you can use the Flag.CACHE_MODE_LOCAL
flag so
that other remote nodes are not queried for data. However the loader will still be used unless the previously
mentioned Flag.SKIP_CACHE_LOAD
is also configured.
If this method is used in a transactional context, note this method will not bring additional values into the
transaction context and thus objects that haven't yet been read will act in a
IsolationLevel.READ_COMMITTED
behavior irrespective of the configured
isolation level. However values that have been previously modified or read that are in the context will be
adhered to. e.g. any write modification or any previous read when using
IsolationLevel.REPEATABLE_READ
This method should only be used for debugging purposes such as to verify that the cache contains all the keys
entered. Any other use involving execution of this method on a production system is not recommended.
public boolean isEmpty()
public boolean containsKey(Object key)
containsKey
in interface Map<K,V>
containsKey
in class AbstractDelegatingCache<K,V>
public boolean containsValue(Object value)
containsValue
in interface Map<K,V>
containsValue
in class AbstractDelegatingCache<K,V>
public Map<K,V> getAll(Set<?> keys)
AdvancedCache
Map
of the values
associated with the set of keys requested.
If the cache is configured read-through, and a get for a key would
return null because an entry is missing from the cache, the Cache's
CacheLoader
is called in an attempt to load the entry. If an
entry cannot be loaded for a given key, the returned Map will contain null for
value of the key.
Unlike other bulk methods if this invoked in an existing transaction all entries will be stored in the current transactional context
The returned Map
will be a copy and updates to the map will not be reflected
in the Cache and vice versa. The keys and values themselves however may not be
copies depending on if storeAsBinary is enabled and the value was retrieved from
the local node.
getAll
in interface AdvancedCache<K,V>
getAll
in class AbstractDelegatingAdvancedCache<K,V>
keys
- The keys whose associated values are to be returned.public void putAll(Map<? extends K,? extends V> map, Metadata metadata)
AdvancedCache
Map.putAll(Map)
, which takes in an instance of
Metadata
which can be used to provide metadata information for
the entries being stored, such as lifespan, version of value...etc.putAll
in interface AdvancedCache<K,V>
putAll
in class AbstractDelegatingAdvancedCache<K,V>
map
- the values to storemetadata
- information to store alongside the value(s)public void clear()
Cache
public CacheSet<K> keySet()
Cache
Set.toArray()
, Set.toArray(Object[])
,
Set.size()
, Set.retainAll(Collection)
and Set.iterator()
methods as they will traverse the entire contents of the cluster including a configured
CacheLoader
and remote entries. The former 2 methods especially have a
very high likely hood of causing a OutOfMemoryError
due to storing all the keys in the entire
cluster in the array.
Use involving execution of this method on a production system is not recommended as they can be quite expensive
operations
Flag.SKIP_CACHE_LOAD
flag should be used to
avoid hitting the cache store as this will cause all entries there to be read in (albeit in a batched form to
prevent OutOfMemoryError
)
Also if you want the local contents only you can use the Flag.CACHE_MODE_LOCAL
flag so
that other remote nodes are not queried for data. However the loader will still be used unless the previously
mentioned Flag.SKIP_CACHE_LOAD
is also configured.
CloseableIteratorSet
interface which creates a
CloseableIterator
instead of a regular one. This means this iterator must be
explicitly closed either through try with resource or calling the close method directly. Technically this iterator
will also close itself if you iterate fully over it, but it is safest to always make sure you close it explicitly.
UnsupportedOperationException
if invoked.
Set.add(Object)
Set.addAll(java.util.Collection)
public Map<K,V> getGroup(String groupName)
AdvancedCache
map
returned is immutable and represents the group at the time of the invocation. If you want to add
or remove keys from a group use BasicCache.put(Object, Object)
and BasicCache.remove(Object)
. To remove all the keys
in the group use AdvancedCache.removeGroup(String)
.
To improve performance you may use the flag
Flag.SKIP_CACHE_LOAD
to avoid
fetching the key/value from persistence. However, you will get an inconsistent snapshot of the group.getGroup
in interface AdvancedCache<K,V>
getGroup
in class AbstractDelegatingAdvancedCache<K,V>
groupName
- the group name.Map
with the key/value pairs.public void removeGroup(String groupName)
AdvancedCache
removeGroup
in interface AdvancedCache<K,V>
removeGroup
in class AbstractDelegatingAdvancedCache<K,V>
groupName
- the group name.public CacheCollection<V> values()
Cache
Collection.toArray()
, Collection.toArray(Object[])
,
Collection.size()
, Collection.retainAll(Collection)
and Collection.iterator()
methods as they will traverse the entire contents of the cluster including a configured
CacheLoader
and remote entries. The former 2 methods especially have a
very high likely hood of causing a OutOfMemoryError
due to storing all the keys in the entire
cluster in the array.
Use involving execution of this method on a production system is not recommended as they can be quite expensive
operations
* Flag.SKIP_CACHE_LOAD
flag should be used to
avoid hitting the cache store as this will cause all entries there to be read in (albeit in a batched form to
prevent OutOfMemoryError
)
Also if you want the local contents only you can use the Flag.CACHE_MODE_LOCAL
flag so
that other remote nodes are not queried for data. However the loader will still be used unless the previously
mentioned Flag.SKIP_CACHE_LOAD
is also configured.
This class implements the CloseableIteratorCollection
interface which creates a
CloseableIterator
instead of a regular one. This means this iterator must be
explicitly closed either through try with resource or calling the close method directly. Technically this iterator
will also close itself if you iterate fully over it, but it is safest to always make sure you close it explicitly.
The iterator retrieved using CloseableIteratorCollection.iterator()
supports the remove method, however the
iterator retrieved from CacheStream.iterator()
will not support remove.
UnsupportedOperationException
if invoked.
Set.add(Object)
Set.addAll(java.util.Collection)
public CacheSet<Map.Entry<K,V>> entrySet()
Cache
Set.toArray()
, Set.toArray(Object[])
,
Set.size()
, Set.retainAll(Collection)
and Set.iterator()
methods as they will traverse the entire contents of the cluster including a configured
CacheLoader
and remote entries. The former 2 methods especially have a
very high likely hood of causing a OutOfMemoryError
due to storing all the keys in the entire
cluster in the array.
Use involving execution of this method on a production system is not recommended as they can be quite expensive
operations
* Flag.SKIP_CACHE_LOAD
flag should be used to
avoid hitting the cache store as this will cause all entries there to be read in (albeit in a batched form to
prevent OutOfMemoryError
)
Also if you want the local contents only you can use the Flag.CACHE_MODE_LOCAL
flag so
that other remote nodes are not queried for data. However the loader will still be used unless the previously
mentioned Flag.SKIP_CACHE_LOAD
is also configured.
Map.Entry#setValue(Object)
and it will update
the cache as well. Also this backing set does allow addition of a new Map.Entry(s) via the
Set.add(Object)
or Set.addAll(java.util.Collection)
methods.
CloseableIteratorSet
interface which creates a
CloseableIterator
instead of a regular one. This means this iterator must be
explicitly closed either through try with resource or calling the close method directly. Technically this iterator
will also close itself if you iterate fully over it, but it is safest to always make sure you close it explicitly.public CacheSet<CacheEntry<K,V>> cacheEntrySet()
AdvancedCache
Cache.entrySet()
but is typed to return CacheEntries instead of Entries. Please see
the other method for a description of its behaviors.
This method is needed since nested generics do not support covariance
cacheEntrySet
in interface AdvancedCache<K,V>
cacheEntrySet
in class AbstractDelegatingAdvancedCache<K,V>
Cache.entrySet()
public V putIfAbsent(K key, V value)
putIfAbsent
in interface ConcurrentMap<K,V>
putIfAbsent
in interface Map<K,V>
putIfAbsent
in class AbstractDelegatingCache<K,V>
public void addListener(Object listener)
Listenable
Listener
and
further to that, contain methods annotated appropriately, otherwise the listener will not be registered.
See the Listener
annotation for more information.
addListener
in interface Listenable
addListener
in class AbstractDelegatingCache<K,V>
listener
- must not be null.public void addListener(Object listener, KeyFilter<? super K> filter)
FilteringListenable
Listener
and
further to that, contain methods annotated appropriately, otherwise the listener will not be registered.
See the Listener
annotation for more information.
addListener
in interface FilteringListenable<K,V>
addListener
in class AbstractDelegatingCache<K,V>
listener
- must not be null.public V put(K key, V value, Metadata metadata)
AdvancedCache
#put(K, V)
, which takes in an instance of
Metadata
which can be used to provide metadata information for
the entry being stored, such as lifespan, version of value...etc.put
in interface AdvancedCache<K,V>
put
in class AbstractDelegatingAdvancedCache<K,V>
key
- key to usevalue
- value to storemetadata
- information to store alongside the valuepublic org.infinispan.commons.util.concurrent.NotifyingFuture<V> putAsync(K key, V value, Metadata metadata)
AdvancedCache
AdvancedCache.put(Object, Object, Metadata)
which stores
metadata alongside the value. This method does not block on remote calls,
even if your cache mode is synchronous. Has no benefit over
AdvancedCache.put(Object, Object, Metadata)
if used in LOCAL mode.
putAsync
in interface AdvancedCache<K,V>
putAsync
in class AbstractDelegatingAdvancedCache<K,V>
key
- key to usevalue
- value to storemetadata
- information to store alongside the new valuepublic V putIfAbsent(K key, V value, Metadata metadata)
AdvancedCache
#putIfAbsent(K, V)
, which takes in an
instance of Metadata
which can be used to provide metadata
information for the entry being stored, such as lifespan, version
of value...etc. The Metadata
is only stored if the call is
successful.putIfAbsent
in interface AdvancedCache<K,V>
putIfAbsent
in class AbstractDelegatingAdvancedCache<K,V>
key
- key with which the specified value is to be associatedvalue
- value to be associated with the specified keymetadata
- information to store alongside the new valuepublic boolean replace(K key, V oldValue, V value, Metadata metadata)
AdvancedCache
#replace(K, V, V)
, which takes in an
instance of Metadata
which can be used to provide metadata
information for the entry being stored, such as lifespan, version
of value...etc. The Metadata
is only stored if the call is
successful.replace
in interface AdvancedCache<K,V>
replace
in class AbstractDelegatingAdvancedCache<K,V>
key
- key with which the specified value is associatedoldValue
- value expected to be associated with the specified keyvalue
- value to be associated with the specified keymetadata
- information to store alongside the new valuepublic V replace(K key, V value, Metadata metadata)
AdvancedCache
#replace(K, V)
, which takes in an
instance of Metadata
which can be used to provide metadata
information for the entry being stored, such as lifespan, version
of value...etc. The Metadata
is only stored if the call is
successful.replace
in interface AdvancedCache<K,V>
replace
in class AbstractDelegatingAdvancedCache<K,V>
key
- key with which the specified value is associatedvalue
- value to be associated with the specified keymetadata
- information to store alongside the new valuepublic CacheEntry getCacheEntry(Object key)
AdvancedCache
getCacheEntry
in interface AdvancedCache<K,V>
getCacheEntry
in class AbstractDelegatingAdvancedCache<K,V>
key
- the key whose associated cache entry is to be returnednull
if this map contains no mapping for the keypublic EntryIterable<K,V> filterEntries(KeyValueFilter<? super K,? super V> filter)
AdvancedCache
Iterable.iterator()
will cause a new request chain to retrieve all of the values in
the cache, including any configured loaders. This iterator is performed in memory sensitive way and thus works
for distributed caches unlike Cache.entrySet()
.
Whenever possible a user should provide a converter through
EntryIterable.converter(org.infinispan.filter.Converter)
to reduce value
payloads or create projection views.
This iterator does not participate in any ongoing transaction that may be present. This is because
IsolationLevel.REPEATABLE_READ
transactions have to keep track of all
the entries they have read (which in this case would include the entries that did not match the filter).
Keeping all the values on a single node would negate the benefits of using a filter and/or converter, and in many
cases it would cause OutOfMemoryErrors. If it is desired to remove entries the
BasicCache.remove(Object)
method or another similar method may be used which would
participate in the transaction
The iterable should always be closed after finished with it, using the standard try/finally or try with resource idioms to ensure that any current resources are freed if an exception prevents full iteration of iterator. Note this will prevent any ongoing iterators that were created from it from progressing further.
filterEntries
in interface AdvancedCache<K,V>
filterEntries
in class AbstractDelegatingAdvancedCache<K,V>
filter
- The filter to use. Note this is required and for distributed caches must be serializable. Callbacks
to the filter will never provide a key or value that will be null.Copyright © 2018 JBoss, a division of Red Hat. All rights reserved.