Interface AdvancedCache<K,V>
-
- All Superinterfaces:
AsyncCache<K,V>
,BasicCache<K,V>
,BatchingCache
,Cache<K,V>
,ConcurrentMap<K,V>
,FilteringListenable<K,V>
,Lifecycle
,Listenable
,Map<K,V>
,TransactionalCache
- All Known Subinterfaces:
SecureCache<K,V>
public interface AdvancedCache<K,V> extends Cache<K,V>, TransactionalCache
An advanced interface that exposes additional methods not available onCache
.- Since:
- 4.0
- Author:
- Manik Surtani, Galder ZamarreƱo, Tristan Tarrant
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Deprecated Methods Modifier and Type Method Description CacheSet<org.infinispan.container.entries.CacheEntry<K,V>>
cacheEntrySet()
Identical toCache.entrySet()
but is typed to return CacheEntries instead of Entries.V
compute(K key, BiFunction<? super K,? super V,? extends V> remappingFunction, Metadata metadata)
An overloaded form of#compute(K, BiFunction)
, which takes in an instance ofMetadata
which can be used to provide metadata information for the entry being stored, such as lifespan, version of value...etc.default V
compute(K key, org.infinispan.util.function.SerializableBiFunction<? super K,? super V,? extends V> remappingFunction, Metadata metadata)
Overloadedcompute(Object, BiFunction, Metadata)
withSerializableBiFunction
CompletableFuture<V>
computeAsync(K key, BiFunction<? super K,? super V,? extends V> remappingFunction, Metadata metadata)
Overloaded#computeAsync(K, BiFunction)
, which stores metadata alongside the value.default CompletableFuture<V>
computeAsync(K key, org.infinispan.util.function.SerializableBiFunction<? super K,? super V,? extends V> remappingFunction, Metadata metadata)
OverloadedcomputeAsync(Object, BiFunction, Metadata)
withSerializableBiFunction
V
computeIfAbsent(K key, Function<? super K,? extends V> mappingFunction, Metadata metadata)
An overloaded form of#computeIfAbsent(K, Function)
, which takes in an instance ofMetadata
which can be used to provide metadata information for the entry being stored, such as lifespan, version of value...etc.default V
computeIfAbsent(K key, org.infinispan.util.function.SerializableFunction<? super K,? extends V> mappingFunction, Metadata metadata)
OverloadedcomputeIfAbsent(Object, Function, Metadata)
withSerializableFunction
CompletableFuture<V>
computeIfAbsentAsync(K key, Function<? super K,? extends V> mappingFunction, Metadata metadata)
Overloaded#computeIfAbsentAsync(K, Function)
, which takes in an instance ofMetadata
which can be used to provide metadata information for the entry being stored, such as lifespan, version of value...etc.default CompletableFuture<V>
computeIfAbsentAsync(K key, org.infinispan.util.function.SerializableFunction<? super K,? extends V> mappingFunction, Metadata metadata)
OverloadedcomputeIfAbsentAsync(Object, Function, Metadata)
withSerializableFunction
V
computeIfPresent(K key, BiFunction<? super K,? super V,? extends V> remappingFunction, Metadata metadata)
An overloaded form of#computeIfPresent(K, BiFunction)
, which takes in an instance ofMetadata
which can be used to provide metadata information for the entry being stored, such as lifespan, version of value...etc.default V
computeIfPresent(K key, org.infinispan.util.function.SerializableBiFunction<? super K,? super V,? extends V> remappingFunction, Metadata metadata)
OverloadedcomputeIfPresent(Object, BiFunction, Metadata)
withSerializableBiFunction
CompletableFuture<V>
computeIfPresentAsync(K key, BiFunction<? super K,? super V,? extends V> remappingFunction, Metadata metadata)
Overloaded#computeIfPresentAsync(K, BiFunction)
, which takes in an instance ofMetadata
which can be used to provide metadata information for the entry being stored, such as lifespan, version of value...etc.default CompletableFuture<V>
computeIfPresentAsync(K key, org.infinispan.util.function.SerializableBiFunction<? super K,? super V,? extends V> remappingFunction, Metadata metadata)
OverloadedcomputeIfPresentAsync(Object, BiFunction, Metadata)
withSerializableBiFunction
Map<K,V>
getAll(Set<?> keys)
Gets a collection of entries, returning them asMap
of the values associated with the set of keys requested.Map<K,org.infinispan.container.entries.CacheEntry<K,V>>
getAllCacheEntries(Set<?> keys)
Gets a collection of entries from theAdvancedCache
, returning them asMap
of the cache entries associated with the set of keys requested.default Map<K,V>
getAndPutAll(Map<? extends K,? extends V> map)
Executes an equivalent ofMap.putAll(Map)
, returning previous values of the modified entries.org.infinispan.interceptors.AsyncInterceptorChain
getAsyncInterceptorChain()
Deprecated.Since 10.0, will be removed without a replacementAuthorizationManager
getAuthorizationManager()
Retrieves theAuthorizationManager
if the cache has security enabled.AvailabilityMode
getAvailability()
Returns the cache's availability.org.infinispan.batch.BatchContainer
getBatchContainer()
Returns the component in charge of batching cache operations.org.infinispan.container.entries.CacheEntry<K,V>
getCacheEntry(Object key)
Retrieves a CacheEntry corresponding to a specific key.default CompletableFuture<org.infinispan.container.entries.CacheEntry<K,V>>
getCacheEntryAsync(Object key)
Retrieves a CacheEntry corresponding to a specific key.ClassLoader
getClassLoader()
Returns the cache loader associated associated with this cache.org.infinispan.factories.ComponentRegistry
getComponentRegistry()
Deprecated.Since 10.0, with no public API replacementDataContainer<K,V>
getDataContainer()
Returns the container where data is stored in the cache.DistributionManager
getDistributionManager()
Retrieves a reference to theDistributionManager
if the cache is configured to use Distribution.EvictionManager
getEvictionManager()
Deprecated.Since 10.1, will be removed without a replacementExpirationManager<K,V>
getExpirationManager()
Map<K,V>
getGroup(String groupName)
It fetches all the keys which belong to the group.org.infinispan.encoding.DataConversion
getKeyDataConversion()
org.infinispan.util.concurrent.locks.LockManager
getLockManager()
Returns the component that deals with all aspects of acquiring and releasing locks for cache entries.org.infinispan.remoting.rpc.RpcManager
getRpcManager()
Returns the component in charge of communication with other caches in the cluster.Stats
getStats()
Returns aStats
object that allows several statistics associated with this cache at runtime.org.infinispan.encoding.DataConversion
getValueDataConversion()
XAResource
getXAResource()
Returns theXAResource
associated with this cache which can be used to do transactional recovery.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.AdvancedCache<K,V>
lockAs(Object lockOwner)
Whenever this cache acquires a lock it will do so using the given Object as the owner of said lock.LockedStream<K,V>
lockedStream()
Returns a sequential stream using this Cache as the source.V
merge(K key, V value, BiFunction<? super V,? super V,? extends V> remappingFunction, Metadata metadata)
An overloaded form ofCache.merge(Object, Object, BiFunction)
, which takes in an instance ofMetadata
which can be used to provide metadata information for the entry being stored, such as lifespan, version of value...etc.default V
merge(K key, V value, org.infinispan.util.function.SerializableBiFunction<? super V,? super V,? extends V> remappingFunction, Metadata metadata)
Overloadedmerge(Object, Object, BiFunction, Metadata)
withSerializableBiFunction
CompletableFuture<V>
mergeAsync(K key, V value, BiFunction<? super V,? super V,? extends V> remappingFunction, Metadata metadata)
OverloadedAsyncCache.mergeAsync(Object, Object, BiFunction)
, which takes in an instance ofMetadata
which can be used to provide metadata information for the entry being stored, such as lifespan, version of value...etc.default CompletableFuture<V>
mergeAsync(K key, V value, org.infinispan.util.function.SerializableBiFunction<? super V,? super V,? extends V> remappingFunction, Metadata metadata)
OverloadedmergeAsync(Object, Object, BiFunction, Metadata)
withSerializableBiFunction
default AdvancedCache<K,V>
noFlags()
Unset all flags set on this cache usingwithFlags(Flag...)
orwithFlags(Collection)
methods.V
put(K key, V value, Metadata metadata)
An overloaded form of#put(K, V)
, which takes in an instance ofMetadata
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> map, Metadata metadata)
An overloaded form ofMap.putAll(Map)
, which takes in an instance ofMetadata
which can be used to provide metadata information for the entries being stored, such as lifespan, version of value...etc.default CompletableFuture<Void>
putAllAsync(Map<? extends K,? extends V> map, Metadata metadata)
CompletableFuture<V>
putAsync(K key, V value, Metadata metadata)
Asynchronous version ofput(Object, Object, Metadata)
which stores metadata alongside the value.void
putForExternalRead(K key, V value, Metadata metadata)
An overloaded form of#putForExternalRead(K, V)
, which takes in an instance ofMetadata
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, Metadata metadata)
An overloaded form of#putIfAbsent(K, V)
, which takes in an instance ofMetadata
which can be used to provide metadata information for the entry being stored, such as lifespan, version of value...etc.default CompletableFuture<V>
putIfAbsentAsync(K key, V value, Metadata metadata)
An overloaded form of#putIfAbsentAsync(K, V)
, which takes in an instance ofMetadata
which can be used to provide metadata information for the entry being stored, such as lifespan, version of value...etc.void
removeGroup(String groupName)
It removes all the key which belongs to a group.CompletableFuture<Boolean>
removeLifespanExpired(K key, V value, Long lifespan)
Attempts to remove the entry if it is expired.CompletableFuture<Boolean>
removeMaxIdleExpired(K key, V value)
Attempts to remove the entry for the given key, if it has expired due to max idle.V
replace(K key, V value, Metadata metadata)
An overloaded form of#replace(K, V)
, which takes in an instance ofMetadata
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, Metadata metadata)
An overloaded form of#replace(K, V, V)
, which takes in an instance ofMetadata
which can be used to provide metadata information for the entry being stored, such as lifespan, version of value...etc.default CompletableFuture<V>
replaceAsync(K key, V value, Metadata metadata)
An overloaded form of#replaceAsync(K, V)
, which takes in an instance ofMetadata
which can be used to provide metadata information for the entry being stored, such as lifespan, version of value...etc.default CompletableFuture<Boolean>
replaceAsync(K key, V oldValue, V newValue, Metadata metadata)
void
setAvailability(AvailabilityMode availabilityMode)
Manually change the availability of the cache.default AdvancedCache<K,V>
transform(Function<AdvancedCache<K,V>,? extends AdvancedCache<K,V>> transformation)
Apply thetransformation
on eachAdvancedCache
instance in a delegation chain, starting with the innermost implementation.AdvancedCache<K,V>
with(ClassLoader classLoader)
Deprecated.Since 9.4, unmarshalling always uses the classloader from the global configuration.AdvancedCache<?,?>
withEncoding(Class<? extends org.infinispan.commons.dataconversion.Encoder> encoder)
Performs any cache operations using the specifiedEncoder
.AdvancedCache<?,?>
withEncoding(Class<? extends org.infinispan.commons.dataconversion.Encoder> keyEncoder, Class<? extends org.infinispan.commons.dataconversion.Encoder> valueEncoder)
Performs any cache operations using the specified pair ofEncoder
.default AdvancedCache<K,V>
withFlags(Collection<Flag> flags)
An alternative towithFlags(Flag...)
not requiring array allocation.default AdvancedCache<K,V>
withFlags(Flag flag)
An alternative towithFlags(Flag...)
optimized for a single flag.AdvancedCache<K,V>
withFlags(Flag... flags)
A method that adds flags to any API call.AdvancedCache<?,?>
withKeyEncoding(Class<? extends org.infinispan.commons.dataconversion.Encoder> encoder)
AdvancedCache<?,?>
withMediaType(String keyMediaType, String valueMediaType)
Perform any cache operations using an alternateMediaType
.AdvancedCache<K,V>
withStorageMediaType()
Perform any cache operations using the sameMediaType
of the cache storage.AdvancedCache<K,V>
withSubject(Subject subject)
Performs any cache operations using the specifiedSubject
.AdvancedCache<K,V>
withWrapping(Class<? extends org.infinispan.commons.dataconversion.Wrapper> wrapper)
Deprecated.Since 11.0.AdvancedCache<K,V>
withWrapping(Class<? extends org.infinispan.commons.dataconversion.Wrapper> keyWrapper, Class<? extends org.infinispan.commons.dataconversion.Wrapper> valueWrapper)
Deprecated.Since 11.0.-
Methods inherited from interface org.infinispan.commons.api.AsyncCache
clearAsync, computeAsync, computeAsync, computeAsync, computeIfAbsentAsync, computeIfAbsentAsync, computeIfAbsentAsync, computeIfPresentAsync, computeIfPresentAsync, computeIfPresentAsync, containsKeyAsync, getAllAsync, getAsync, mergeAsync, mergeAsync, mergeAsync, putAllAsync, putAllAsync, putAllAsync, putAsync, putAsync, putAsync, putIfAbsentAsync, putIfAbsentAsync, putIfAbsentAsync, removeAsync, removeAsync, replaceAsync, replaceAsync, replaceAsync, replaceAsync, replaceAsync, replaceAsync, sizeAsync
-
Methods inherited from interface org.infinispan.commons.api.BasicCache
compute, compute, computeIfAbsent, computeIfAbsent, computeIfPresent, computeIfPresent, getName, getVersion, merge, merge, put, put, put, putAll, putAll, putIfAbsent, putIfAbsent, remove, replace, replace, replace, replace
-
Methods inherited from interface org.infinispan.commons.api.BatchingCache
endBatch, startBatch
-
Methods inherited from interface org.infinispan.Cache
clear, compute, compute, compute, compute, computeAsync, computeAsync, computeAsync, computeIfAbsent, computeIfAbsent, computeIfAbsent, computeIfAbsent, computeIfAbsentAsync, computeIfAbsentAsync, computeIfAbsentAsync, computeIfPresent, computeIfPresent, computeIfPresentAsync, entrySet, evict, getAdvancedCache, getCacheConfiguration, getCacheManager, getStatus, keySet, merge, merge, merge, merge, mergeAsync, mergeAsync, mergeAsync, putForExternalRead, putForExternalRead, putForExternalRead, shutdown, size, stop, values
-
Methods inherited from interface org.infinispan.notifications.FilteringListenable
addFilteredListener, addFilteredListenerAsync, addListener, addListenerAsync, addStorageFormatFilteredListener, addStorageFormatFilteredListenerAsync
-
Methods inherited from interface org.infinispan.notifications.Listenable
addListener, addListenerAsync, getListeners, removeListener, removeListenerAsync
-
Methods inherited from interface org.infinispan.commons.api.TransactionalCache
getTransactionManager
-
-
-
-
Method Detail
-
withFlags
AdvancedCache<K,V> withFlags(Flag... flags)
A method that adds flags to any API call. For example, consider the following code snippet: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 should also consider saving the decorated cache, as this allows for more readable code. E.g.:AdvancedCache<?, ?> forceWriteLockCache = cache.withFlags(Flag.FORCE_WRITE_LOCK); forceWriteLockCache.get(key1); forceWriteLockCache.get(key2); forceWriteLockCache.get(key3);
- Parameters:
flags
- a set of flags to apply. See theFlag
documentation.- Returns:
- an
AdvancedCache
instance on which a real operation is to be invoked, if the flags are to be applied.
-
withFlags
default AdvancedCache<K,V> withFlags(Collection<Flag> flags)
An alternative towithFlags(Flag...)
not requiring array allocation.- Since:
- 9.2
-
withFlags
default AdvancedCache<K,V> withFlags(Flag flag)
An alternative towithFlags(Flag...)
optimized for a single flag.- Since:
- 10.0
-
noFlags
default AdvancedCache<K,V> noFlags()
Unset all flags set on this cache usingwithFlags(Flag...)
orwithFlags(Collection)
methods.- Returns:
- Cache not applying any flags to the command; possibly
this
.
-
transform
default AdvancedCache<K,V> transform(Function<AdvancedCache<K,V>,? extends AdvancedCache<K,V>> transformation)
Apply thetransformation
on eachAdvancedCache
instance in a delegation chain, starting with the innermost implementation.- Parameters:
transformation
-- Returns:
- The outermost transformed cache.
-
withSubject
AdvancedCache<K,V> withSubject(Subject subject)
Performs any cache operations using the specifiedSubject
. Only applies to caches with authorization enabled (seeConfigurationBuilder.security()
).- Parameters:
subject
-- Returns:
- an
AdvancedCache
instance on which a real operation is to be invoked, using the specified subject
-
getAsyncInterceptorChain
@Deprecated org.infinispan.interceptors.AsyncInterceptorChain getAsyncInterceptorChain()
Deprecated.Since 10.0, will be removed without a replacementAllows the modification of the interceptor chain.
-
getEvictionManager
@Deprecated EvictionManager getEvictionManager()
Deprecated.Since 10.1, will be removed without a replacement- Returns:
- the eviction manager - if one is configured - for this cache instance
-
getExpirationManager
ExpirationManager<K,V> getExpirationManager()
- Returns:
- the expiration manager - if one is configured - for this cache instance
-
getComponentRegistry
@Deprecated org.infinispan.factories.ComponentRegistry getComponentRegistry()
Deprecated.Since 10.0, with no public API replacement- Returns:
- the component registry for this cache instance
-
getDistributionManager
DistributionManager getDistributionManager()
Retrieves a reference to theDistributionManager
if the cache is configured to use Distribution. Otherwise, returns a null.- Returns:
- a DistributionManager, or null.
-
getAuthorizationManager
AuthorizationManager getAuthorizationManager()
Retrieves theAuthorizationManager
if the cache has security enabled. Otherwise returns null- Returns:
- an AuthorizationManager or null
-
lockAs
AdvancedCache<K,V> lockAs(Object lockOwner)
Whenever this cache acquires a lock it will do so using the given Object as the owner of said lock.This can be useful when a lock may have been manually acquired and you wish to reuse that lock across invocations.
Great care should be taken with this command as misuse can very easily lead to deadlocks.
- Parameters:
lockOwner
- the lock owner to lock any keys as- Returns:
- an
AdvancedCache
instance on which when an operation is invoked it will use lock owner object to acquire any locks
-
lock
boolean lock(K... keys)
Locks a given key or keys eagerly across cache nodes in a cluster.Keys can be locked eagerly in the context of a transaction only.
- Parameters:
keys
- the keys to lock- Returns:
- true if the lock acquisition attempt was successful for all keys; false will only be returned if
the lock acquisition timed out and the operation has been called with
Flag.FAIL_SILENTLY
. - Throws:
org.infinispan.util.concurrent.TimeoutException
- if the lock cannot be acquired within the configured lock acquisition time.
-
lock
boolean lock(Collection<? extends K> keys)
Locks collections of keys eagerly across cache nodes in a cluster.Collections of keys can be locked eagerly in the context of a transaction only.
- Parameters:
keys
- collection of keys to lock- Returns:
- true if the lock acquisition attempt was successful for all keys; false will only be returned if
the lock acquisition timed out and the operation has been called with
Flag.FAIL_SILENTLY
. - Throws:
org.infinispan.util.concurrent.TimeoutException
- if the lock cannot be acquired within the configured lock acquisition time.
-
getRpcManager
org.infinispan.remoting.rpc.RpcManager getRpcManager()
Returns the component in charge of communication with other caches in the cluster. If the cache'sClusteringConfiguration.cacheMode()
isCacheMode.LOCAL
, this method will return null.- Returns:
- the RPC manager component associated with this cache instance or null
-
getBatchContainer
org.infinispan.batch.BatchContainer getBatchContainer()
Returns the component in charge of batching cache operations.- Returns:
- the batching component associated with this cache instance
-
getDataContainer
DataContainer<K,V> getDataContainer()
Returns the container where data is stored in the cache. Users should interact with this component with care because direct calls on it bypass the internal interceptors and other infrastructure in place to guarantee the consistency of data.- Returns:
- the data container associated with this cache instance
-
getLockManager
org.infinispan.util.concurrent.locks.LockManager getLockManager()
Returns the component that deals with all aspects of acquiring and releasing locks for cache entries.- Returns:
- retrieves the lock manager associated with this cache instance
-
getStats
Stats getStats()
Returns aStats
object that allows several statistics associated with this cache at runtime.- Returns:
- this cache's
Stats
object
-
getXAResource
XAResource getXAResource()
Returns theXAResource
associated with this cache which can be used to do transactional recovery.- Returns:
- an instance of
XAResource
-
getClassLoader
ClassLoader getClassLoader()
Returns the cache loader associated associated with this cache. As an alternative to setting this on every invocation, users could also consider using theDecoratedCache
wrapper.- Returns:
- this cache's cache loader
-
with
@Deprecated AdvancedCache<K,V> with(ClassLoader classLoader)
Deprecated.Since 9.4, unmarshalling always uses the classloader from the global configuration.
-
put
V put(K key, V value, Metadata metadata)
An overloaded form of#put(K, V)
, which takes in an instance ofMetadata
which can be used to provide metadata information for the entry being stored, such as lifespan, version of value...etc.- Parameters:
key
- key to usevalue
- value to storemetadata
- information to store alongside the value- Returns:
- the previous value associated with key, or null if there was no mapping for key.
- Since:
- 5.3
-
putAll
void putAll(Map<? extends K,? extends V> map, Metadata metadata)
An overloaded form ofMap.putAll(Map)
, which takes in an instance ofMetadata
which can be used to provide metadata information for the entries being stored, such as lifespan, version of value...etc.- Parameters:
map
- the values to storemetadata
- information to store alongside the value(s)- Since:
- 7.2
-
putAllAsync
default CompletableFuture<Void> putAllAsync(Map<? extends K,? extends V> map, Metadata metadata)
-
replace
V replace(K key, V value, Metadata metadata)
An overloaded form of#replace(K, V)
, which takes in an instance ofMetadata
which can be used to provide metadata information for the entry being stored, such as lifespan, version of value...etc. TheMetadata
is only stored if the call is successful.- Parameters:
key
- key with which the specified value is associatedvalue
- value to be associated with the specified keymetadata
- information to store alongside the new value- Returns:
- the previous value associated with the specified key, or null if there was no mapping for the key.
- Since:
- 5.3
-
replaceAsync
default CompletableFuture<V> replaceAsync(K key, V value, Metadata metadata)
An overloaded form of#replaceAsync(K, V)
, which takes in an instance ofMetadata
which can be used to provide metadata information for the entry being stored, such as lifespan, version of value...etc. TheMetadata
is only stored if the call is successful.- Parameters:
key
- key with which the specified value is associatedvalue
- value to be associated with the specified keymetadata
- information to store alongside the new value- Returns:
- the future that contains previous value associated with the specified key, or null if there was no mapping for the key.
- Since:
- 9.2
-
replace
boolean replace(K key, V oldValue, V newValue, Metadata metadata)
An overloaded form of#replace(K, V, V)
, which takes in an instance ofMetadata
which can be used to provide metadata information for the entry being stored, such as lifespan, version of value...etc. TheMetadata
is only stored if the call is successful.- Parameters:
key
- key with which the specified value is associatedoldValue
- value expected to be associated with the specified keynewValue
- value to be associated with the specified keymetadata
- information to store alongside the new value- Returns:
- true if the value was replaced
- Since:
- 5.3
-
replaceAsync
default CompletableFuture<Boolean> replaceAsync(K key, V oldValue, V newValue, Metadata metadata)
-
putIfAbsent
V putIfAbsent(K key, V value, Metadata metadata)
An overloaded form of#putIfAbsent(K, V)
, which takes in an instance ofMetadata
which can be used to provide metadata information for the entry being stored, such as lifespan, version of value...etc. TheMetadata
is only stored if the call is successful.- Parameters:
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 value- Returns:
- the previous value associated with the specified key, or null if there was no mapping for the key.
- Since:
- 5.3
-
putIfAbsentAsync
default CompletableFuture<V> putIfAbsentAsync(K key, V value, Metadata metadata)
An overloaded form of#putIfAbsentAsync(K, V)
, which takes in an instance ofMetadata
which can be used to provide metadata information for the entry being stored, such as lifespan, version of value...etc. TheMetadata
is only stored if the call is successful.- Parameters:
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 value- Returns:
- A future containing the previous value associated with the specified key, or null if there was no mapping for the key.
- Since:
- 9.2
-
putForExternalRead
void putForExternalRead(K key, V value, Metadata metadata)
An overloaded form of#putForExternalRead(K, V)
, which takes in an instance ofMetadata
which can be used to provide metadata information for the entry being stored, such as lifespan, version of value...etc. TheMetadata
is only stored if the call is successful.- Parameters:
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 value- Since:
- 7.0
-
compute
V compute(K key, BiFunction<? super K,? super V,? extends V> remappingFunction, Metadata metadata)
An overloaded form of#compute(K, BiFunction)
, which takes in an instance ofMetadata
which can be used to provide metadata information for the entry being stored, such as lifespan, version of value...etc.- Parameters:
key
- key with which the specified value is associatedremappingFunction
- function to be applied to the specified key/valuemetadata
- information to store alongside the new value- Returns:
- the previous value associated with the specified key, or null if remapping function is gives null.
- Since:
- 9.1
-
compute
default V compute(K key, org.infinispan.util.function.SerializableBiFunction<? super K,? super V,? extends V> remappingFunction, Metadata metadata)
Overloadedcompute(Object, BiFunction, Metadata)
withSerializableBiFunction
-
computeIfPresent
V computeIfPresent(K key, BiFunction<? super K,? super V,? extends V> remappingFunction, Metadata metadata)
An overloaded form of#computeIfPresent(K, BiFunction)
, which takes in an instance ofMetadata
which can be used to provide metadata information for the entry being stored, such as lifespan, version of value...etc. TheMetadata
is only stored if the call is successful.- Parameters:
key
- key with which the specified value is associatedremappingFunction
- function to be applied to the specified key/valuemetadata
- information to store alongside the new value- Returns:
- the previous value associated with the specified key, or null if there was no mapping for the key.
- Since:
- 9.1
-
computeIfPresent
default V computeIfPresent(K key, org.infinispan.util.function.SerializableBiFunction<? super K,? super V,? extends V> remappingFunction, Metadata metadata)
OverloadedcomputeIfPresent(Object, BiFunction, Metadata)
withSerializableBiFunction
-
computeIfAbsent
V computeIfAbsent(K key, Function<? super K,? extends V> mappingFunction, Metadata metadata)
An overloaded form of#computeIfAbsent(K, Function)
, which takes in an instance ofMetadata
which can be used to provide metadata information for the entry being stored, such as lifespan, version of value...etc. TheMetadata
is only stored if the call is successful.- Parameters:
key
- key with which the specified value is associatedmappingFunction
- function to be applied to the specified keymetadata
- information to store alongside the new value- Returns:
- the value created with the mapping function associated with the specified key, or the previous value associated with the specified key if the key is not absent.
- Since:
- 9.1
-
computeIfAbsent
default V computeIfAbsent(K key, org.infinispan.util.function.SerializableFunction<? super K,? extends V> mappingFunction, Metadata metadata)
OverloadedcomputeIfAbsent(Object, Function, Metadata)
withSerializableFunction
-
merge
V merge(K key, V value, BiFunction<? super V,? super V,? extends V> remappingFunction, Metadata metadata)
An overloaded form ofCache.merge(Object, Object, BiFunction)
, which takes in an instance ofMetadata
which can be used to provide metadata information for the entry being stored, such as lifespan, version of value...etc. TheMetadata
is only stored if the call is successful.- Parameters:
key
- , key with which the resulting value is to be associatedvalue
- , the non-null value to be merged with the existing value associated with the key or, if no existing value or a null value is associated with the key, to be associated with the keyremappingFunction
- , the function to recompute a value if presentmetadata
- , information to store alongside the new value- Returns:
- the new value associated with the specified key, or null if no value is associated with the key
- Since:
- 9.2
-
merge
default V merge(K key, V value, org.infinispan.util.function.SerializableBiFunction<? super V,? super V,? extends V> remappingFunction, Metadata metadata)
Overloadedmerge(Object, Object, BiFunction, Metadata)
withSerializableBiFunction
-
putAsync
CompletableFuture<V> putAsync(K key, V value, Metadata metadata)
Asynchronous version ofput(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 overput(Object, Object, Metadata)
if used in LOCAL mode.- Parameters:
key
- key to usevalue
- value to storemetadata
- information to store alongside the new value- Returns:
- a future containing the old value replaced.
- Since:
- 5.3
-
computeAsync
CompletableFuture<V> computeAsync(K key, BiFunction<? super K,? super V,? extends V> remappingFunction, Metadata metadata)
Overloaded#computeAsync(K, BiFunction)
, which stores metadata alongside the value. This method does not block on remote calls, even if your cache mode is synchronous.- Parameters:
key
- key with which the specified value is associatedremappingFunction
- function to be applied to the specified key/valuemetadata
- information to store alongside the new value- Returns:
- the previous value associated with the specified key, or null if remapping function is gives null.
- Since:
- 9.4
-
computeAsync
default CompletableFuture<V> computeAsync(K key, org.infinispan.util.function.SerializableBiFunction<? super K,? super V,? extends V> remappingFunction, Metadata metadata)
OverloadedcomputeAsync(Object, BiFunction, Metadata)
withSerializableBiFunction
- Since:
- 9.4
-
computeIfPresentAsync
CompletableFuture<V> computeIfPresentAsync(K key, BiFunction<? super K,? super V,? extends V> remappingFunction, Metadata metadata)
Overloaded#computeIfPresentAsync(K, BiFunction)
, which takes in an instance ofMetadata
which can be used to provide metadata information for the entry being stored, such as lifespan, version of value...etc. TheMetadata
is only stored if the call is successful.- Parameters:
key
- key with which the specified value is associatedremappingFunction
- function to be applied to the specified key/valuemetadata
- information to store alongside the new value- Returns:
- the previous value associated with the specified key, or null if there was no mapping for the key.
- Since:
- 9.4
-
computeIfPresentAsync
default CompletableFuture<V> computeIfPresentAsync(K key, org.infinispan.util.function.SerializableBiFunction<? super K,? super V,? extends V> remappingFunction, Metadata metadata)
OverloadedcomputeIfPresentAsync(Object, BiFunction, Metadata)
withSerializableBiFunction
- Since:
- 9.4
-
computeIfAbsentAsync
CompletableFuture<V> computeIfAbsentAsync(K key, Function<? super K,? extends V> mappingFunction, Metadata metadata)
Overloaded#computeIfAbsentAsync(K, Function)
, which takes in an instance ofMetadata
which can be used to provide metadata information for the entry being stored, such as lifespan, version of value...etc. TheMetadata
is only stored if the call is successful.- Parameters:
key
- key with which the specified value is associatedmappingFunction
- function to be applied to the specified keymetadata
- information to store alongside the new value- Returns:
- the value created with the mapping function associated with the specified key, or the previous value associated with the specified key if the key is not absent.
- Since:
- 9.4
-
computeIfAbsentAsync
default CompletableFuture<V> computeIfAbsentAsync(K key, org.infinispan.util.function.SerializableFunction<? super K,? extends V> mappingFunction, Metadata metadata)
OverloadedcomputeIfAbsentAsync(Object, Function, Metadata)
withSerializableFunction
- Since:
- 9.4
-
mergeAsync
CompletableFuture<V> mergeAsync(K key, V value, BiFunction<? super V,? super V,? extends V> remappingFunction, Metadata metadata)
OverloadedAsyncCache.mergeAsync(Object, Object, BiFunction)
, which takes in an instance ofMetadata
which can be used to provide metadata information for the entry being stored, such as lifespan, version of value...etc. TheMetadata
is only stored if the call is successful.- Parameters:
key
- , key with which the resulting value is to be associatedvalue
- , the non-null value to be merged with the existing value associated with the key or, if no existing value or a null value is associated with the key, to be associated with the keyremappingFunction
- , the function to recompute a value if presentmetadata
- , information to store alongside the new value- Returns:
- the new value associated with the specified key, or null if no value is associated with the key
- Since:
- 9.4
-
mergeAsync
default CompletableFuture<V> mergeAsync(K key, V value, org.infinispan.util.function.SerializableBiFunction<? super V,? super V,? extends V> remappingFunction, Metadata metadata)
OverloadedmergeAsync(Object, Object, BiFunction, Metadata)
withSerializableBiFunction
-
getAll
Map<K,V> getAll(Set<?> keys)
Gets a collection of entries, returning them asMap
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.- Parameters:
keys
- The keys whose associated values are to be returned.- Returns:
- A map of entries that were found for the given keys. If an entry is not found for a given key, it will not be in the returned map.
- Throws:
NullPointerException
- if keys is null or if keys contains a null
-
getCacheEntry
org.infinispan.container.entries.CacheEntry<K,V> getCacheEntry(Object key)
Retrieves a CacheEntry corresponding to a specific key.- Parameters:
key
- the key whose associated cache entry is to be returned- Returns:
- the cache entry to which the specified key is mapped, or
null
if this map contains no mapping for the key - Since:
- 5.3
-
getCacheEntryAsync
default CompletableFuture<org.infinispan.container.entries.CacheEntry<K,V>> getCacheEntryAsync(Object key)
Retrieves a CacheEntry corresponding to a specific key.- Parameters:
key
- the key whose associated cache entry is to be returned- Returns:
- a future with the cache entry to which the specified key is mapped, or with
null
if this map contains no mapping for the key - Since:
- 9.2
-
getAllCacheEntries
Map<K,org.infinispan.container.entries.CacheEntry<K,V>> getAllCacheEntries(Set<?> keys)
Gets a collection of entries from theAdvancedCache
, returning them asMap
of the cache entries 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.- Parameters:
keys
- The keys whose associated values are to be returned.- Returns:
- A map of entries that were found for the given keys. Keys not found in the cache are present in the map with null values.
- Throws:
NullPointerException
- if keys is null or if keys contains a null
-
getAndPutAll
default Map<K,V> getAndPutAll(Map<? extends K,? extends V> map)
Executes an equivalent ofMap.putAll(Map)
, returning previous values of the modified entries.- Parameters:
map
- mappings to be stored in this map- Returns:
- A map of previous values for the given keys. If the previous mapping does not exist it will not be in the returned map.
- Since:
- 9.1
-
getGroup
Map<K,V> getGroup(String groupName)
It fetches all the keys which belong to the group. Semantically, it iterates over all the keys in memory and persistence, and performs a read operation in the keys found. Multiple invocations inside a transaction ensures that all the keys previous read are returned and it may return newly added keys to the group from other committed transactions (also known as phantom reads). Themap
returned is immutable and represents the group at the time of the invocation. If you want to add or remove keys from a group useBasicCache.put(Object, Object)
andBasicCache.remove(Object)
. To remove all the keys in the group useremoveGroup(String)
. To improve performance you may use theflag
Flag.SKIP_CACHE_LOAD
to avoid fetching the key/value from persistence. However, you will get an inconsistent snapshot of the group.- Parameters:
groupName
- the group name.- Returns:
- an immutable
Map
with the key/value pairs.
-
removeGroup
void removeGroup(String groupName)
It removes all the key which belongs to a group. Semantically, it fetches the most recent group keys/values and removes them. Note that, concurrent addition perform by other transactions/threads to the group may not be removed.- Parameters:
groupName
- the group name.
-
getAvailability
AvailabilityMode getAvailability()
Returns the cache's availability. In local mode this method will always returnAvailabilityMode.AVAILABLE
. In clustered mode, thePartitionHandlingManager
is queried to obtain the availability mode.
-
setAvailability
void setAvailability(AvailabilityMode availabilityMode)
Manually change the availability of the cache. Doesn't change anything if the cache is not clustered orPartitionHandlingConfiguration.whenSplit()
is set toPartitionHandling.ALLOW_READ_WRITES
.
-
cacheEntrySet
CacheSet<org.infinispan.container.entries.CacheEntry<K,V>> cacheEntrySet()
Identical toCache.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
- Returns:
- the entry set containing all of the CacheEntries
- See Also:
Cache.entrySet()
-
lockedStream
LockedStream<K,V> lockedStream()
Returns a sequential stream using this Cache as the source. This stream is very similar to using theCacheStream
returned from theCacheCollection.stream()
method of the collection returned viacacheEntrySet()
. The use of this locked stream is that when an entry is being processed by the user the entry is locked for the invocation preventing a different thread from modifying it.Note that this stream is not supported when using a optimistic transactional or simple cache. Both non transactional and pessimistic transactional caches are supported.
The stream will not share any ongoing transaction the user may have. Code executed by the stream should be treated as completely independent. That is any operation performed via the stream will require the user to start their own transaction or will be done intrinsically on the invocation. Note that if there is an ongoing transaction that has a lock on a key from the cache, that it will cause a deadlock.
Currently simple cache,
ConfigurationBuilder.simpleCache(boolean)
was set to true, and optimistic caches,TransactionConfigurationBuilder.lockingMode(LockingMode)
was set toLockingMode.OPTIMISTIC
, do not support this method. In this case it will throw anUnsupportedOperationException
. This restriction may be removed in a future version. Also this method cannot be used on a cache that has a lock owner already specified vialockAs(Object)
as this could lead to a deadlock or the release of locks early and will throw anIllegalStateException
.- Returns:
- the locked stream
- Throws:
UnsupportedOperationException
- this is thrown if invoked from a cache that doesn't support thisIllegalStateException
- if this cache has already explicitly set a lock owner- Since:
- 9.1
-
removeLifespanExpired
CompletableFuture<Boolean> removeLifespanExpired(K key, V value, Long lifespan)
Attempts to remove the entry if it is expired. Due to expired entries not being consistent across nodes, this will still attempt to remove the value if it is not present. Note that this will raise an expired event even if the entry is not present. Normally this method should never be invoked except by theExpirationManager
.This command will only remove the value if the value and lifespan also match if provided.
This method will suspend any ongoing transaction and start a new one just for the invocation of this command. It is automatically committed or rolled back after the command completes, either successfully or via an exception.
NOTE: This method may be removed at any point including in a minor release and is not supported for external usage.
- Parameters:
key
- the key that is expiringvalue
- the value that mapped to the given. Null means it will match any valuelifespan
- the lifespan that should match. If null is provided it will match any lifespan value- Returns:
- if the entry was removed
-
removeMaxIdleExpired
CompletableFuture<Boolean> removeMaxIdleExpired(K key, V value)
Attempts to remove the entry for the given key, if it has expired due to max idle. This command first locks the key and then verifies that the entry has expired via maxIdle across all nodes. If it has this will then remove the given key.This method returns a boolean when it has determined if the entry has expired. This is useful for when a backup node invokes this command for a get that found the entry expired. This way the node can return back to the caller much faster when the entry is not expired and do any additional processing asynchronously if needed.
This method will suspend any ongoing transaction and start a new one just for the invocation of this command. It is automatically committed or rolled back after the command completes, either successfully or via an exception.
NOTE: This method may be removed at any point including in a minor release and is not supported for external usage.
- Parameters:
key
- the key that expired via max idle for the given entry- Returns:
- if the entry was removed
-
withEncoding
AdvancedCache<?,?> withEncoding(Class<? extends org.infinispan.commons.dataconversion.Encoder> keyEncoder, Class<? extends org.infinispan.commons.dataconversion.Encoder> valueEncoder)
Performs any cache operations using the specified pair ofEncoder
.- Parameters:
keyEncoder
-Encoder
for the keys.valueEncoder
-Encoder
for the values.- Returns:
- an instance of
AdvancedCache
where all operations will use the supplied encoders.
-
withWrapping
AdvancedCache<K,V> withWrapping(Class<? extends org.infinispan.commons.dataconversion.Wrapper> keyWrapper, Class<? extends org.infinispan.commons.dataconversion.Wrapper> valueWrapper)
Deprecated.Since 11.0. To be removed in 14.0, with no replacement.Performs any cache operations using the specified pair ofWrapper
.- Parameters:
keyWrapper
-Wrapper
for the keys.valueWrapper
-Wrapper
for the values.- Returns:
AdvancedCache
where all operations will use the supplied wrappers.
-
withEncoding
AdvancedCache<?,?> withEncoding(Class<? extends org.infinispan.commons.dataconversion.Encoder> encoder)
Performs any cache operations using the specifiedEncoder
.- Parameters:
encoder
-Encoder
used for both keys and values.- Returns:
- an instance of
AdvancedCache
where all operations will use the supplied encoder.
-
withWrapping
AdvancedCache<K,V> withWrapping(Class<? extends org.infinispan.commons.dataconversion.Wrapper> wrapper)
Deprecated.Since 11.0. To be removed in 14.0, with no replacement.Performs any cache operations using the specifiedWrapper
.- Parameters:
wrapper
-Wrapper
for the keys and values.- Returns:
- an instance of
AdvancedCache
where all operations will use the supplied wrapper.
-
withMediaType
AdvancedCache<?,?> withMediaType(String keyMediaType, String valueMediaType)
Perform any cache operations using an alternateMediaType
.- Parameters:
keyMediaType
-MediaType
for the keys.valueMediaType
-org.infinispan.commons.dataconversion
for the values.- Returns:
- an instance of
AdvancedCache
where all data will formatted according to the suppliedMediaType
.
-
withStorageMediaType
AdvancedCache<K,V> withStorageMediaType()
Perform any cache operations using the sameMediaType
of the cache storage. This is equivalent to disabling transcoding on the cache.- Returns:
- an instance of
AdvancedCache
where no data conversion will take place.
-
getKeyDataConversion
org.infinispan.encoding.DataConversion getKeyDataConversion()
- Returns:
- The associated
DataConversion
for the keys.
-
getValueDataConversion
org.infinispan.encoding.DataConversion getValueDataConversion()
- Returns:
- The associated
DataConversion
for the cache's values.
-
withKeyEncoding
AdvancedCache<?,?> withKeyEncoding(Class<? extends org.infinispan.commons.dataconversion.Encoder> encoder)
-
-