Interface IgniteCache<K,V>
-
- Type Parameters:
K
- Cache key type.V
- Cache value type.
- All Superinterfaces:
AutoCloseable
,javax.cache.Cache<K,V>
,Closeable
,IgniteAsyncSupport
,Iterable<javax.cache.Cache.Entry<K,V>>
public interface IgniteCache<K,V> extends javax.cache.Cache<K,V>, IgniteAsyncSupport
Main entry point for all Data Grid APIs. You can get a named cache by callingIgnite.cache(String)
method.Functionality
This API extendsCache
API which containsJCache (JSR107)
cache functionality and documentation. In addition toCache
functionality this API provides:- Ability to perform basic atomic Map-like operations available on
JCache
API. - Ability to bulk load cache via
loadCache(IgniteBiPredicate, Object...)
method. - Distributed lock functionality via
lock(Object)
methods. - Ability to query cache using Predicate, SQL, and Text queries via
query(Query)
method. - Ability to collect cache and query metrics.
- Ability to force partition rebalancing via
rebalance()
methopd (in case if delayed rebalancing was configured.) - Ability to peek into memory without doing actual
get(...)
from cache vialocalPeek(Object, CachePeekMode...)
methods - Ability to evict and promote entries from on-heap to off-heap or swap and back.
- Ability to atomically collocate compute and data via
invoke(Object, CacheEntryProcessor, Object...)
methods.
Transactions
Cache API supports transactions. You can group and set of cache methods within a transaction to provide ACID-compliant behavior. SeeIgniteTransactions
for more information.
Methods which can be used inside transaction (put, get...) throw TransactionException. SeeTransactionException
for more information.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Deprecated Methods Modifier and Type Method Description void
clear()
Clears the contents of the cache, without notifying listeners orCacheWriter
s.void
clear(K key)
Clears entry from the cache and swap storage, without notifying listeners orCacheWriter
s.void
clearAll(Set<? extends K> keys)
Clears entries from the cache and swap storage, without notifying listeners orCacheWriter
s.IgniteFuture<Void>
clearAllAsync(Set<? extends K> keys)
Asynchronously clears entries from the cache and swap storage, without notifying listeners orCacheWriter
s.IgniteFuture<Void>
clearAsync()
Asynchronously clears the contents of the cache, without notifying listeners orCacheWriter
s.IgniteFuture<Void>
clearAsync(K key)
Asynchronously clears entry from the cache and swap storage, without notifying listeners orCacheWriter
s.void
clearStatistics()
Clear cluster statistics for this cache.void
close()
Closes this cache instance.boolean
containsKey(K key)
IgniteFuture<Boolean>
containsKeyAsync(K key)
Asynchronously determines if theCache
contains an entry for the specified key.boolean
containsKeys(Set<? extends K> keys)
Determines if theCache
contains entries for the specified keys.IgniteFuture<Boolean>
containsKeysAsync(Set<? extends K> keys)
Asynchronously determines if theCache
contains entries for the specified keys.void
destroy()
Completely deletes the cache with all its data from the system on all cluster nodes.void
enableStatistics(boolean enabled)
Sets statistics enabled flag cluster wide for this cache.V
get(K key)
Map<K,V>
getAll(Set<? extends K> keys)
IgniteFuture<Map<K,V>>
getAllAsync(Set<? extends K> keys)
Asynchronously gets a collection of entries from theCache
, returning them asMap
of the values associated with the set of keys requested.Map<K,V>
getAllOutTx(Set<? extends K> keys)
Gets values from cache.IgniteFuture<Map<K,V>>
getAllOutTxAsync(Set<? extends K> keys)
Asynchronously gets values from cache.V
getAndPut(K key, V val)
IgniteFuture<V>
getAndPutAsync(K key, V val)
Asynchronously associates the specified value with the specified key in this cache, returning an existing value if one existed as the future result.V
getAndPutIfAbsent(K key, V val)
Stores given key-value pair in cache only if cache had no previous mapping for it.IgniteFuture<V>
getAndPutIfAbsentAsync(K key, V val)
Asynchronously stores given key-value pair in cache only if cache had no previous mapping for it.V
getAndRemove(K key)
IgniteFuture<V>
getAndRemoveAsync(K key)
Asynchronously removes the entry for a key only if currently mapped to some value.V
getAndReplace(K key, V val)
IgniteFuture<V>
getAndReplaceAsync(K key, V val)
Asynchronously replaces the value for a given key if and only if there is a value currently mapped by the key.IgniteFuture<V>
getAsync(K key)
Asynchronously gets an entry from the cache.<C extends javax.cache.configuration.Configuration<K,V>>
CgetConfiguration(Class<C> clazz)
Collection<CacheEntry<K,V>>
getEntries(Set<? extends K> keys)
Gets a collection of entries from theCache
.IgniteFuture<Collection<CacheEntry<K,V>>>
getEntriesAsync(Set<? extends K> keys)
Asynchronously gets a collection of entries from theCache
.CacheEntry<K,V>
getEntry(K key)
Gets an entry from the cache.IgniteFuture<CacheEntry<K,V>>
getEntryAsync(K key)
Asynchronously gets an entry from the cache.IgniteFuture<?>
indexReadyFuture()
Returns future that will be completed when all indexes for this cache are ready to use.<T> T
invoke(K key, javax.cache.processor.EntryProcessor<K,V,T> entryProcessor, Object... arguments)
<T> T
invoke(K key, CacheEntryProcessor<K,V,T> entryProcessor, Object... arguments)
Invokes anCacheEntryProcessor
against theCache.Entry
specified by the provided key.<T> Map<K,javax.cache.processor.EntryProcessorResult<T>>
invokeAll(Map<? extends K,? extends javax.cache.processor.EntryProcessor<K,V,T>> map, Object... args)
Asynchronously invokes eachEntryProcessor
from map's values against the correspondentCache.Entry
specified by map's key set.<T> Map<K,javax.cache.processor.EntryProcessorResult<T>>
invokeAll(Set<? extends K> keys, javax.cache.processor.EntryProcessor<K,V,T> entryProcessor, Object... args)
<T> Map<K,javax.cache.processor.EntryProcessorResult<T>>
invokeAll(Set<? extends K> keys, CacheEntryProcessor<K,V,T> entryProcessor, Object... args)
Invokes anCacheEntryProcessor
against the set ofCache.Entry
s specified by the set of keys.<T> IgniteFuture<Map<K,javax.cache.processor.EntryProcessorResult<T>>>
invokeAllAsync(Map<? extends K,? extends javax.cache.processor.EntryProcessor<K,V,T>> map, Object... args)
Asynchronous version of theinvokeAll(Map, Object...)
method.<T> IgniteFuture<Map<K,javax.cache.processor.EntryProcessorResult<T>>>
invokeAllAsync(Set<? extends K> keys, javax.cache.processor.EntryProcessor<K,V,T> entryProcessor, Object... args)
Asynchronously invokes anEntryProcessor
against the set ofCache.Entry
s specified by the set of keys.<T> IgniteFuture<Map<K,javax.cache.processor.EntryProcessorResult<T>>>
invokeAllAsync(Set<? extends K> keys, CacheEntryProcessor<K,V,T> entryProcessor, Object... args)
Asynchronously invokes anCacheEntryProcessor
against the set ofCache.Entry
s specified by the set of keys.<T> IgniteFuture<T>
invokeAsync(K key, javax.cache.processor.EntryProcessor<K,V,T> entryProcessor, Object... arguments)
Asynchronously invokes anEntryProcessor
against theCache.Entry
specified by the provided key.<T> IgniteFuture<T>
invokeAsync(K key, CacheEntryProcessor<K,V,T> entryProcessor, Object... arguments)
Asynchronously invokes anCacheEntryProcessor
against theCache.Entry
specified by the provided key.boolean
isLocalLocked(K key, boolean byCurrThread)
Checks if specified key is locked.void
loadCache(@Nullable IgniteBiPredicate<K,V> p, @Nullable Object... args)
ExecuteslocalLoadCache(IgniteBiPredicate, Object...)
on all cache nodes.IgniteFuture<Void>
loadCacheAsync(@Nullable IgniteBiPredicate<K,V> p, @Nullable Object... args)
Asynchronously executeslocalLoadCache(IgniteBiPredicate, Object...)
on all cache nodes.void
localClear(K key)
Clears entry from the cache and swap storage, without notifying listeners orCacheWriter
s.void
localClearAll(Set<? extends K> keys)
Clears entries from the cache and swap storage, without notifying listeners orCacheWriter
s.Iterable<javax.cache.Cache.Entry<K,V>>
localEntries(CachePeekMode... peekModes)
Allows for iteration over local cache entries.void
localEvict(Collection<? extends K> keys)
Attempts to evict all entries associated with keys.void
localLoadCache(@Nullable IgniteBiPredicate<K,V> p, @Nullable Object... args)
Delegates toCacheStore.loadCache(IgniteBiInClosure,Object...)
method to load state from the underlying persistent storage.IgniteFuture<Void>
localLoadCacheAsync(@Nullable IgniteBiPredicate<K,V> p, @Nullable Object... args)
Asynchronously loads state from the underlying persistent storage by delegating toCacheStore.loadCache(IgniteBiInClosure,Object...)
method.CacheMetrics
localMetrics()
Gets local snapshot metrics (statistics) for this cache.V
localPeek(K key, CachePeekMode... peekModes)
Peeks at a value in the local storage using an optional peek mode.boolean
localPreloadPartition(int partition)
Efficiently preloads cache partition into page memory if it exists on the local node.int
localSize(CachePeekMode... peekModes)
Gets the number of all entries cached on this node.long
localSizeLong(int partition, CachePeekMode... peekModes)
Gets the number of all entries cached on this node for the partition as a long value.long
localSizeLong(CachePeekMode... peekModes)
Gets the number of all entries cached on this node as a long value.Lock
lock(K key)
Creates aLock
instance associated with passed key.Lock
lockAll(Collection<? extends K> keys)
Deprecated.It is recommended to useIgnite.reentrantLock(String, boolean, boolean, boolean)
instead.Collection<Integer>
lostPartitions()
Gets a collection of lost partition IDs.CacheMetrics
metrics()
Gets whole cluster snapshot metrics (statistics) for this cache.CacheMetrics
metrics(ClusterGroup grp)
Gets cluster group snapshot metrics for caches in cluster group.void
preloadPartition(int partition)
Efficiently preloads cache primary partition into page memory.IgniteFuture<Void>
preloadPartitionAsync(int partition)
Efficiently preloads cache partition into page memory.void
put(K key, V val)
void
putAll(Map<? extends K,? extends V> map)
IgniteFuture<Void>
putAllAsync(Map<? extends K,? extends V> map)
Asynchronously copies all of the entries from the specified map to theCache
.IgniteFuture<Void>
putAsync(K key, V val)
Asynchronously associates the specified value with the specified key in the cache.boolean
putIfAbsent(K key, V val)
IgniteFuture<Boolean>
putIfAbsentAsync(K key, V val)
Asynchronously associates the specified key with the given value if it is not already associated with a value.<R> QueryCursor<R>
query(Query<R> qry)
Queries cache.<T,R>
QueryCursor<R>query(Query<T> qry, IgniteClosure<T,R> transformer)
Queries the cache transforming the entries on the server nodes.FieldsQueryCursor<List<?>>
query(SqlFieldsQuery qry)
Queries cache.Collection<? extends QueryDetailMetrics>
queryDetailMetrics()
Gets query detail metrics.QueryMetrics
queryMetrics()
Gets query metrics.IgniteFuture<Boolean>
rebalance()
Deprecated.Use baseline topology feature instead.boolean
remove(K key)
boolean
remove(K key, V oldVal)
void
removeAll()
Removes all of the mappings from this cache.void
removeAll(Set<? extends K> keys)
IgniteFuture<Void>
removeAllAsync()
Asynchronously removes all of the mappings from this cache.IgniteFuture<Void>
removeAllAsync(Set<? extends K> keys)
Asynchronously removes entries for the specified keys.IgniteFuture<Boolean>
removeAsync(K key)
Asynchronously removes the mapping for a key from this cache if it is present.IgniteFuture<Boolean>
removeAsync(K key, V oldVal)
Asynchronously removes the mapping for a key only if currently mapped to the given value.boolean
replace(K key, V val)
boolean
replace(K key, V oldVal, V newVal)
IgniteFuture<Boolean>
replaceAsync(K key, V val)
Asynchronously replaces the entry for a key only if currently mapped to a given value.IgniteFuture<Boolean>
replaceAsync(K key, V oldVal, V newVal)
Asynchronous version of thereplace(Object, Object, Object)
.void
resetQueryDetailMetrics()
Reset query detail metrics.void
resetQueryMetrics()
Reset query metrics.int
size(CachePeekMode... peekModes)
Gets the number of all entries cached across all nodes.IgniteFuture<Integer>
sizeAsync(CachePeekMode... peekModes)
Asynchronously gets the number of all entries cached across all nodes.long
sizeLong(int partition, CachePeekMode... peekModes)
Gets the number of all entries cached in a partition as a long value.long
sizeLong(CachePeekMode... peekModes)
Gets the number of all entries cached across all nodes as a long value.IgniteFuture<Long>
sizeLongAsync(int partition, CachePeekMode... peekModes)
Asynchronously gets the number of all entries cached in a partition as a long value.IgniteFuture<Long>
sizeLongAsync(CachePeekMode... peekModes)
Asynchronously gets the number of all entries cached across all nodes as a long value.IgniteCache<K,V>
withAsync()
Deprecated.IgniteCache<K,V>
withExpiryPolicy(javax.cache.expiry.ExpiryPolicy plc)
Returns cache with the specified expired policy set.<K1,V1>
IgniteCache<K1,V1>withKeepBinary()
Returns cache that will operate with binary objects.IgniteCache<K,V>
withNoRetries()
IgniteCache<K,V>
withPartitionRecover()
Gets an instance ofIgniteCache
that will be allowed to execute cache read operations regardless of partition loss policy.IgniteCache<K,V>
withReadRepair(ReadRepairStrategy strategy)
This is an experimental API.IgniteCache<K,V>
withSkipStore()
-
Methods inherited from interface javax.cache.Cache
deregisterCacheEntryListener, getCacheManager, getName, isClosed, iterator, loadAll, registerCacheEntryListener, unwrap
-
Methods inherited from interface org.apache.ignite.lang.IgniteAsyncSupport
future, isAsync
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Method Detail
-
withAsync
@Deprecated IgniteCache<K,V> withAsync()
Deprecated.Gets instance of this component with asynchronous mode enabled.- Specified by:
withAsync
in interfaceIgniteAsyncSupport
- Returns:
- Instance of this component with asynchronous mode enabled.
-
getConfiguration
<C extends javax.cache.configuration.Configuration<K,V>> C getConfiguration(Class<C> clazz)
-
withExpiryPolicy
IgniteCache<K,V> withExpiryPolicy(javax.cache.expiry.ExpiryPolicy plc)
Returns cache with the specified expired policy set. This policy will be used for each operation invoked on the returned cache.This method does not modify existing cache instance.
- Parameters:
plc
- Expire policy to use.- Returns:
- Cache instance with the specified expiry policy set.
-
withSkipStore
IgniteCache<K,V> withSkipStore()
- Returns:
- Cache with read-through write-through behavior disabled.
-
withNoRetries
IgniteCache<K,V> withNoRetries()
- Returns:
- Cache with no-retries behavior enabled.
-
withPartitionRecover
IgniteCache<K,V> withPartitionRecover()
Gets an instance ofIgniteCache
that will be allowed to execute cache read operations regardless of partition loss policy.- Returns:
- Cache without partition loss protection.
-
withReadRepair
IgniteCache<K,V> withReadRepair(ReadRepairStrategy strategy)
This is an experimental API.Gets an instance of
IgniteCache
that will perform backup nodes check on each get attempt.Read Repair means that each backup node will be checked to have the same entry as the primary node has.
In case consistency violations were found, the values across the topology will be replaced by repaired values according to the chosen strategy, see
ReadRepairStrategy
for the details.A consistency violation exception will be thrown when the repair is impossible.
CacheConsistencyViolationEvent
will be recorded for each violation in case it's configured as recordable.- For transactional caches, values will be repaired:
- automatically for transactions that have
TransactionConcurrency.OPTIMISTIC
concurrency mode orTransactionIsolation.READ_COMMITTED
isolation level, - at commit() phase for transactions that have
TransactionConcurrency.PESSIMISTIC
concurrency mode and isolation level other thanTransactionIsolation.READ_COMMITTED
This proxy usage does not guarantee "all copies check" in case the value have been already cached inside the transaction. In case you don't use a READ_COMMITTED isolation mode and already have a cached value, for example have already read the value or performed a write, you'll just get the cached value.
- automatically for transactions that have
- For atomic caches, values will be repaired automatically.
Warning:
Due to the nature of an atomic cache, false-positive results can be observed. For example, an attempt to check consistency under cache's loading may lead to a consistency violation exception. By default, the implementation tries to check the given key three times. The number of attempts can be changed using
IgniteSystemProperties.IGNITE_NEAR_GET_MAX_REMAPS
property.
- Caches without backups.
- Near caches.
- Caches that use "read-through" mode.
Full list of repairable methods:
containsKey(K)
&&containsKeyAsync(K)
containsKeys(java.util.Set<? extends K>)
&&containsKeysAsync(java.util.Set<? extends K>)
getEntry(K)
&&getEntryAsync(K)
getEntries(java.util.Set<? extends K>)
&&getEntriesAsync(java.util.Set<? extends K>)
get(K)
&&getAsync(K)
getAll(java.util.Set<? extends K>)
&&getAllAsync(java.util.Set<? extends K>)
- Parameters:
strategy
- Read Repair strategy.- Returns:
- Cache with explicit consistency check on each read and repair if necessary.
- For transactional caches, values will be repaired:
-
withKeepBinary
<K1,V1> IgniteCache<K1,V1> withKeepBinary()
Returns cache that will operate with binary objects.Cache returned by this method will not be forced to deserialize binary objects, so keys and values will be returned from cache API methods without changes. Therefore, signature of the cache can contain only following types:
org.apache.ignite.binary.BinaryObject
for binary classes- All primitives (byte, int, ...) and there boxed versions (Byte, Integer, ...)
- Arrays of primitives (byte[], int[], ...)
String
and array ofString
sUUID
and array ofUUID
sDate
and array ofDate
sTimestamp
and array ofTimestamp
s- Enums and array of enums
- Maps, collections and array of objects (but objects inside them will still be converted if they are binary)
For example, if you use
Integer
as a key andValue
class as a value (which will be stored in binary format), you should acquire following projection to avoid deserialization:IgniteCache<Integer, BinaryObject> prj = cache.withKeepBinary(); // Value is not deserialized and returned in binary format. BinaryObject po = prj.get(1);
Note that this method makes sense only if cache is working in binary mode if default marshaller is used. If not, this method is no-op and will return current cache.
- Type Parameters:
V1
- Type of the cache value binary objects.K1
- Type of the cache key.- Returns:
- New cache instance for binary objects.
-
loadCache
@IgniteAsyncSupported void loadCache(@Nullable @Nullable IgniteBiPredicate<K,V> p, @Nullable @Nullable Object... args) throws javax.cache.CacheException
ExecuteslocalLoadCache(IgniteBiPredicate, Object...)
on all cache nodes.- Parameters:
p
- Optional predicate (may benull
). If provided, will be used to filter values loaded from storage before they are put into cache.args
- Optional user arguments to be passed intoCacheStore.loadCache(IgniteBiInClosure, Object...)
method.- Throws:
javax.cache.CacheException
- If loading failed.
-
loadCacheAsync
IgniteFuture<Void> loadCacheAsync(@Nullable @Nullable IgniteBiPredicate<K,V> p, @Nullable @Nullable Object... args) throws javax.cache.CacheException
Asynchronously executeslocalLoadCache(IgniteBiPredicate, Object...)
on all cache nodes.- Parameters:
p
- Optional predicate (may benull
). If provided, will be used to filter values loaded from storage before they are put into cache.args
- Optional user arguments to be passed intoCacheStore.loadCache(IgniteBiInClosure, Object...)
method.- Returns:
- a Future representing pending completion of the cache loading.
- Throws:
javax.cache.CacheException
- If loading failed.
-
localLoadCache
@IgniteAsyncSupported void localLoadCache(@Nullable @Nullable IgniteBiPredicate<K,V> p, @Nullable @Nullable Object... args) throws javax.cache.CacheException
Delegates toCacheStore.loadCache(IgniteBiInClosure,Object...)
method to load state from the underlying persistent storage. The loaded values will then be given to the optionally passed in predicate, and, if the predicate returnstrue
, will be stored in cache. If predicate isnull
, then all loaded values will be stored in cache.Note that this method does not receive keys as a parameter, so it is up to
CacheStore
implementation to provide all the data to be loaded.This method is not transactional and may end up loading a stale value into cache if another thread has updated the value immediately after it has been loaded. It is mostly useful when pre-loading the cache from underlying data store before start, or for read-only caches.
- Parameters:
p
- Optional predicate (may benull
). If provided, will be used to filter values to be put into cache.args
- Optional user arguments to be passed intoCacheStore.loadCache(IgniteBiInClosure, Object...)
method.- Throws:
javax.cache.CacheException
- If loading failed.
-
localLoadCacheAsync
IgniteFuture<Void> localLoadCacheAsync(@Nullable @Nullable IgniteBiPredicate<K,V> p, @Nullable @Nullable Object... args) throws javax.cache.CacheException
Asynchronously loads state from the underlying persistent storage by delegating toCacheStore.loadCache(IgniteBiInClosure,Object...)
method. The loaded values will then be given to the optionally passed in predicate, and, if the predicate returnstrue
, will be stored in cache. If predicate isnull
, then all loaded values will be stored in cache.Note that this method does not receive keys as a parameter, so it is up to
CacheStore
implementation to provide all the data to be loaded.This method is not transactional and may end up loading a stale value into cache if another thread has updated the value immediately after it has been loaded. It is mostly useful when pre-loading the cache from underlying data store before start, or for read-only caches.
- Parameters:
p
- Optional predicate (may benull
). If provided, will be used to filter values to be put into cache.args
- Optional user arguments to be passed intoCacheStore.loadCache(IgniteBiInClosure, Object...)
method.- Returns:
- a Future representing pending completion of the cache loading.
- Throws:
javax.cache.CacheException
- If loading failed.
-
getAndPutIfAbsent
@IgniteAsyncSupported V getAndPutIfAbsent(K key, V val) throws javax.cache.CacheException, TransactionException
Stores given key-value pair in cache only if cache had no previous mapping for it. If cache previously contained value for the given key, then this value is returned. In case ofCacheMode.PARTITIONED
orCacheMode.REPLICATED
caches, the value will be loaded from the primary node, which in its turn may load the value from the swap storage, and consecutively, if it's not in swap, from the underlying persistent storage. If value has to be loaded from persistent storage,CacheLoader.load(Object)
method will be used.If the returned value is not needed, method
putIfAbsent(Object, Object)
should always be used instead of this one to avoid the overhead associated with returning of the previous value.If write-through is enabled, the stored value will be persisted to
CacheStore
viaCacheWriter.write(javax.cache.Cache.Entry)
method.Transactions
This method is transactional and will enlist the entry into ongoing transaction if there is one.- Parameters:
key
- Key to store in cache.val
- Value to be associated with the given key.- Returns:
- Previously contained value regardless of whether put happened or not (
null
if there was no previous value). - Throws:
NullPointerException
- If either key or value arenull
.javax.cache.CacheException
- If put operation failed.TransactionException
- If operation within transaction is failed.
-
getAndPutIfAbsentAsync
IgniteFuture<V> getAndPutIfAbsentAsync(K key, V val) throws javax.cache.CacheException, TransactionException
Asynchronously stores given key-value pair in cache only if cache had no previous mapping for it. If cache previously contained value for the given key, then this value is returned. In case ofCacheMode.PARTITIONED
orCacheMode.REPLICATED
caches, the value will be loaded from the primary node, which in its turn may load the value from the swap storage, and consecutively, if it's not in swap, from the underlying persistent storage. If value has to be loaded from persistent storage,CacheLoader.load(Object)
method will be used.If the returned value is not needed, method
putIfAbsentAsync(Object, Object)
should always be used instead of this one to avoid the overhead associated with returning of the previous value.If write-through is enabled, the stored value will be persisted to
CacheStore
viaCacheWriter.write(javax.cache.Cache.Entry)
method.Transactions
This method is transactional and will enlist the entry into ongoing transaction if there is one.- Parameters:
key
- Key to store in cache.val
- Value to be associated with the given key.- Returns:
- a Future representing pending completion of the operation.
- Throws:
NullPointerException
- If either key or value arenull
.javax.cache.CacheException
- If put operation failed.TransactionException
- If operation within transaction is failed.
-
lock
Lock lock(K key)
Creates aLock
instance associated with passed key. This method does not acquire lock immediately, you have to call appropriate method on returned instance. Returned lock does not supportLock.newCondition()
method, other methods defined inLock
are supported.- Parameters:
key
- Key for lock.- Returns:
- New lock instance associated with passed key.
- See Also:
Lock.lock()
,Lock.tryLock(long, TimeUnit)
-
lockAll
Lock lockAll(Collection<? extends K> keys)
Deprecated.It is recommended to useIgnite.reentrantLock(String, boolean, boolean, boolean)
instead. This method will be removed in future releases.Creates aLock
instance associated with passed keys. This method does not acquire lock immediately, you have to call appropriate method on returned instance. Returned lock does not supportLock.newCondition()
method, other methods defined inLock
are supported.- Parameters:
keys
- Keys for lock.- Returns:
- New lock instance associated with passed key.
- See Also:
Lock.lock()
,Lock.tryLock(long, TimeUnit)
-
isLocalLocked
boolean isLocalLocked(K key, boolean byCurrThread)
Checks if specified key is locked.This is a local in-VM operation and does not involve any network trips or access to persistent storage in any way.
- Parameters:
key
- Key to check.byCurrThread
- Iftrue
method will check that current thread owns a lock on this key, otherwise will check that any thread on any node owns a lock on this key.- Returns:
True
if lock is owned by some node.
-
query
<R> QueryCursor<R> query(Query<R> qry)
Queries cache. Accepts any subclass ofQuery
interface. See alsoquery(SqlFieldsQuery)
.- Type Parameters:
R
- Type of the query result.- Parameters:
qry
- Query.- Returns:
- Cursor.
- See Also:
ScanQuery
,SqlFieldsQuery
,TextQuery
,SpiQuery
-
query
FieldsQueryCursor<List<?>> query(SqlFieldsQuery qry)
Queries cache. AcceptsSqlFieldsQuery
class.- Parameters:
qry
- SqlFieldsQuery.- Returns:
- Cursor.
- See Also:
SqlFieldsQuery
-
query
<T,R> QueryCursor<R> query(Query<T> qry, IgniteClosure<T,R> transformer)
Queries the cache transforming the entries on the server nodes. Can be used, for example, to avoid network overhead in case only one field out of the large is required by client.Currently transformers are supported ONLY for
ScanQuery
. Passing any other subclass ofQuery
interface to this method will end up withUnsupportedOperationException
.- Type Parameters:
T
- Type of the initial query result.R
- Type of the transformed query result.- Parameters:
qry
- Query.transformer
- Transformer.- Returns:
- Cursor.
-
localEntries
Iterable<javax.cache.Cache.Entry<K,V>> localEntries(CachePeekMode... peekModes) throws javax.cache.CacheException
Allows for iteration over local cache entries.- Parameters:
peekModes
- Peek modes.- Returns:
- Iterable over local cache entries.
- Throws:
javax.cache.CacheException
- If failed.
-
queryMetrics
QueryMetrics queryMetrics()
Gets query metrics.- Returns:
- Metrics.
-
resetQueryMetrics
void resetQueryMetrics()
Reset query metrics.
-
queryDetailMetrics
Collection<? extends QueryDetailMetrics> queryDetailMetrics()
Gets query detail metrics. Query detail metrics could be enabled viaCacheConfiguration.setQueryDetailMetricsSize(int)
method.- Returns:
- Metrics.
-
resetQueryDetailMetrics
void resetQueryDetailMetrics()
Reset query detail metrics.
-
localEvict
void localEvict(Collection<? extends K> keys)
Attempts to evict all entries associated with keys. Note, that entry will be evicted only if it's not used (not participating in any locks or transactions).- Parameters:
keys
- Keys to evict.
-
localPeek
V localPeek(K key, CachePeekMode... peekModes)
Peeks at a value in the local storage using an optional peek mode.This method will not load a value from the configured
CacheStore
or from a remote node.Transactions
This method does not participate in any transactions.- Parameters:
key
- Entry key.peekModes
- Peek modes.- Returns:
- Peeked value, or
null
if not found. - Throws:
NullPointerException
- If key isnull
.
-
size
@IgniteAsyncSupported int size(CachePeekMode... peekModes) throws javax.cache.CacheException
Gets the number of all entries cached across all nodes. By default, ifpeekModes
value isn't defined, only size of primary copies across all nodes will be returned. This behavior is identical to calling this method withCachePeekMode.PRIMARY
peek mode.NOTE: this operation is distributed and will query all participating nodes for their cache sizes.
- Parameters:
peekModes
- Optional peek modes. If not provided, then total cache size is returned.- Returns:
- Cache size across all nodes.
- Throws:
javax.cache.CacheException
- On error.
-
sizeAsync
IgniteFuture<Integer> sizeAsync(CachePeekMode... peekModes) throws javax.cache.CacheException
Asynchronously gets the number of all entries cached across all nodes. By default, ifpeekModes
value isn't defined, only size of primary copies across all nodes will be returned. This behavior is identical to calling this method withCachePeekMode.PRIMARY
peek mode.NOTE: this operation is distributed and will query all participating nodes for their cache sizes.
- Parameters:
peekModes
- Optional peek modes. If not provided, then total cache size is returned.- Returns:
- a Future representing pending completion of the operation.
- Throws:
javax.cache.CacheException
- On error.
-
sizeLong
@IgniteAsyncSupported long sizeLong(CachePeekMode... peekModes) throws javax.cache.CacheException
Gets the number of all entries cached across all nodes as a long value. By default, ifpeekModes
value isn't defined, only size of primary copies across all nodes will be returned. This behavior is identical to calling this method withCachePeekMode.PRIMARY
peek mode.NOTE: this operation is distributed and will query all participating nodes for their cache sizes.
- Parameters:
peekModes
- Optional peek modes. If not provided, then total cache size is returned.- Returns:
- Cache size across all nodes.
- Throws:
javax.cache.CacheException
- On error.
-
sizeLongAsync
IgniteFuture<Long> sizeLongAsync(CachePeekMode... peekModes) throws javax.cache.CacheException
Asynchronously gets the number of all entries cached across all nodes as a long value. By default, ifpeekModes
value isn't defined, only size of primary copies across all nodes will be returned. This behavior is identical to calling this method withCachePeekMode.PRIMARY
peek mode.NOTE: this operation is distributed and will query all participating nodes for their cache sizes.
- Parameters:
peekModes
- Optional peek modes. If not provided, then total cache size is returned.- Returns:
- a Future representing pending completion of the operation.
- Throws:
javax.cache.CacheException
- On error.
-
sizeLong
@IgniteAsyncSupported long sizeLong(int partition, CachePeekMode... peekModes) throws javax.cache.CacheException
Gets the number of all entries cached in a partition as a long value. By default, ifpeekModes
value isn't defined, only size of primary copies across all nodes will be returned. This behavior is identical to calling this method withCachePeekMode.PRIMARY
peek mode.NOTE: this operation is distributed and will query all participating nodes for their partition cache sizes.
- Parameters:
partition
- partition.peekModes
- Optional peek modes. If not provided, then total partition cache size is returned.- Returns:
- Partition cache size across all nodes.
- Throws:
javax.cache.CacheException
- On error.
-
sizeLongAsync
IgniteFuture<Long> sizeLongAsync(int partition, CachePeekMode... peekModes) throws javax.cache.CacheException
Asynchronously gets the number of all entries cached in a partition as a long value. By default, ifpeekModes
value isn't defined, only size of primary copies across all nodes will be returned. This behavior is identical to calling this method withCachePeekMode.PRIMARY
peek mode.NOTE: this operation is distributed and will query all participating nodes for their partition cache sizes.
- Parameters:
partition
- partition.peekModes
- Optional peek modes. If not provided, then total partition cache size is returned.- Returns:
- a Future representing pending completion of the operation.
- Throws:
javax.cache.CacheException
- On error.
-
localSize
int localSize(CachePeekMode... peekModes)
Gets the number of all entries cached on this node. By default, ifpeekModes
value isn't defined, only size of primary copies will be returned. This behavior is identical to calling this method withCachePeekMode.PRIMARY
peek mode.- Parameters:
peekModes
- Optional peek modes. If not provided, then total cache size is returned.- Returns:
- Cache size on this node.
-
localSizeLong
long localSizeLong(CachePeekMode... peekModes)
Gets the number of all entries cached on this node as a long value. By default, ifpeekModes
value isn't defined, only size of primary copies will be returned. This behavior is identical to calling this method withCachePeekMode.PRIMARY
peek mode.- Parameters:
peekModes
- Optional peek modes. If not provided, then total cache size is returned.- Returns:
- Cache size on this node.
-
localSizeLong
long localSizeLong(int partition, CachePeekMode... peekModes)
Gets the number of all entries cached on this node for the partition as a long value. By default, ifpeekModes
value isn't defined, only size of primary copies will be returned. This behavior is identical to calling this method withCachePeekMode.PRIMARY
peek mode.- Parameters:
partition
- partition.peekModes
- Optional peek modes. If not provided, then total cache size is returned.- Returns:
- Cache size on this node.
-
invokeAll
@IgniteAsyncSupported <T> Map<K,javax.cache.processor.EntryProcessorResult<T>> invokeAll(Map<? extends K,? extends javax.cache.processor.EntryProcessor<K,V,T>> map, Object... args) throws TransactionException
Asynchronously invokes eachEntryProcessor
from map's values against the correspondentCache.Entry
specified by map's key set.If an
Cache.Entry
does not exist for the specified key, an attempt is made to load it (if a loader is configured) or a surrogateCache.Entry
, consisting of the key and a value of null is provided.The order that the entries for the keys are processed is undefined. Implementations may choose to process the entries in any order, including concurrently. Furthermore there is no guarantee implementations will use the same
EntryProcessor
instance to process each entry, as the case may be in a non-local cache topology.The result of executing the
EntryProcessor
is returned in the future as aMap
ofEntryProcessorResult
s, one result per key. Should theEntryProcessor
or Caching implementation throw an exception, the exception is wrapped and re-thrown when a call toEntryProcessorResult.get()
is made.Please refer to documentation for
CacheAtomicityMode.ATOMIC
for information on system behavior in crash scenarios for atomic caches.Keys are locked in the order in which they appear in map. It is caller's responsibility to make sure keys always follow same order, such as by using
TreeMap
. Using unordered map, such asHashMap
, while calling this method in parallel will lead to deadlock.- Type Parameters:
T
- Type of the cache entry processing result.- Parameters:
map
- Map containing keys and entry processors to be applied to values.args
- Additional arguments to pass to theEntryProcessor
.- Returns:
- The map of
EntryProcessorResult
s of the processing per key, if any, defined by theEntryProcessor
implementation. No mappings will be returned forEntryProcessor
s that return anull
value for a key. - Throws:
TransactionException
- If operation within transaction is failed.
-
invokeAllAsync
<T> IgniteFuture<Map<K,javax.cache.processor.EntryProcessorResult<T>>> invokeAllAsync(Map<? extends K,? extends javax.cache.processor.EntryProcessor<K,V,T>> map, Object... args) throws TransactionException
Asynchronous version of theinvokeAll(Map, Object...)
method.- Type Parameters:
T
- Type of the cache entry processing result.- Parameters:
map
- Map containing keys and entry processors to be applied to values.args
- Additional arguments to pass to theEntryProcessor
.- Returns:
- a Future representing pending completion of the operation. See more about future result
at the
invokeAll(Map, Object...)
. - Throws:
TransactionException
- If operation within transaction is failed.
-
get
@IgniteAsyncSupported V get(K key) throws TransactionException
- Specified by:
get
in interfacejavax.cache.Cache<K,V>
- Throws:
TransactionException
- If operation within transaction is failed.
-
getAsync
IgniteFuture<V> getAsync(K key)
Asynchronously gets an entry from the cache.If the cache is configured to use read-through, and a future result would be null because the entry is missing from the cache, the Cache's
CacheLoader
is called in an attempt to load the entry.- Parameters:
key
- Key.- Returns:
- a Future representing pending completion of the operation.
-
getEntry
@IgniteAsyncSupported CacheEntry<K,V> getEntry(K key) throws TransactionException
Gets an entry from the cache.If the cache is configured to use read-through, and get would return null because the entry is missing from the cache, the Cache's
CacheLoader
is called in an attempt to load the entry.- Parameters:
key
- The key whose associated value is to be returned.- Returns:
- The element, or null, if it does not exist.
- Throws:
IllegalStateException
- If the cache isCache.isClosed()
.NullPointerException
- If the key isnull
.javax.cache.CacheException
- If there is a problem fetching the value.ClassCastException
- If the implementation is configured to perform runtime-type-checking, and the key or value types are incompatible with those that have been configured for theCache
.TransactionException
- If operation within transaction is failed.
-
getEntryAsync
IgniteFuture<CacheEntry<K,V>> getEntryAsync(K key) throws TransactionException
Asynchronously gets an entry from the cache.If the cache is configured to use read-through, and a future result would be null because the entry is missing from the cache, the Cache's
CacheLoader
is called in an attempt to load the entry.- Parameters:
key
- The key whose associated value is to be returned.- Returns:
- a Future representing pending completion of the operation.
- Throws:
IllegalStateException
- If the cache isCache.isClosed()
.NullPointerException
- If the key isnull
.javax.cache.CacheException
- If there is a problem fetching the value.ClassCastException
- If the implementation is configured to perform runtime-type-checking, and the key or value types are incompatible with those that have been configured for theCache
.TransactionException
- If operation within transaction is failed.
-
getAll
@IgniteAsyncSupported Map<K,V> getAll(Set<? extends K> keys) throws TransactionException
- Specified by:
getAll
in interfacejavax.cache.Cache<K,V>
- Throws:
TransactionException
- If operation within transaction is failed.
-
getAllAsync
IgniteFuture<Map<K,V>> getAllAsync(Set<? extends K> keys) throws TransactionException
Asynchronously gets a collection of entries from theCache
, returning them asMap
of the values associated with the set of keys requested.If the cache is configured read-through, and a future result for a key would be 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 key will not be present in the returned Map.- Parameters:
keys
- Keys set.- Returns:
- a Future representing pending completion of the operation.
- Throws:
TransactionException
- If operation within transaction is failed.
-
getEntries
@IgniteAsyncSupported Collection<CacheEntry<K,V>> getEntries(Set<? extends K> keys) throws TransactionException
Gets a collection of entries from theCache
.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 key will not be present in the returned Collection.- Parameters:
keys
- The keys whose associated values are to be returned.- Returns:
- A collection of entries that were found for the given keys. Entries not found in the cache are not in the returned collection.
- Throws:
NullPointerException
- If keys is null or if keys contains anull
.IllegalStateException
- If the cache isCache.isClosed()
.javax.cache.CacheException
- If there is a problem fetching the values.ClassCastException
- If the implementation is configured to perform runtime-type-checking, and the key or value types are incompatible with those that have been configured for theCache
.TransactionException
- If operation within transaction is failed.
-
getEntriesAsync
IgniteFuture<Collection<CacheEntry<K,V>>> getEntriesAsync(Set<? extends K> keys) throws TransactionException
Asynchronously gets a collection of entries from theCache
.If the cache is configured read-through, and a future result for a key would be 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 key will not be present in the returned Collection.- Parameters:
keys
- The keys whose associated values are to be returned.- Returns:
- a Future representing pending completion of the operation.
- Throws:
NullPointerException
- If keys is null or if keys contains anull
.IllegalStateException
- If the cache isCache.isClosed()
.javax.cache.CacheException
- If there is a problem fetching the values.ClassCastException
- If the implementation is configured to perform runtime-type-checking, and the key or value types are incompatible with those that have been configured for theCache
.TransactionException
- If operation within transaction is failed.
-
getAllOutTx
@IgniteAsyncSupported Map<K,V> getAllOutTx(Set<? extends K> keys)
Gets values from cache. Will bypass started transaction, if any, i.e. will not enlist entries and will not lock any keys if pessimistic transaction is started by thread.- Parameters:
keys
- The keys whose associated values are to be returned.- Returns:
- A map of entries that were found for the given keys.
-
getAllOutTxAsync
IgniteFuture<Map<K,V>> getAllOutTxAsync(Set<? extends K> keys)
Asynchronously gets values from cache. Will bypass started transaction, if any, i.e. will not enlist entries and will not lock any keys if pessimistic transaction is started by thread.- Parameters:
keys
- The keys whose associated values are to be returned.- Returns:
- a Future representing pending completion of the operation.
-
containsKey
@IgniteAsyncSupported boolean containsKey(K key) throws TransactionException
- Specified by:
containsKey
in interfacejavax.cache.Cache<K,V>
- Throws:
TransactionException
- If operation within transaction is failed.
-
containsKeyAsync
IgniteFuture<Boolean> containsKeyAsync(K key) throws TransactionException
Asynchronously determines if theCache
contains an entry for the specified key.More formally, future result is true if and only if this cache contains a mapping for a key k such that key.equals(k). (There can be at most one such mapping.)
- Parameters:
key
- Key.- Returns:
- a Future representing pending completion of the operation.
- Throws:
TransactionException
- If operation within transaction is failed.
-
containsKeys
@IgniteAsyncSupported boolean containsKeys(Set<? extends K> keys) throws TransactionException
Determines if theCache
contains entries for the specified keys.- Parameters:
keys
- Key whose presence in this cache is to be tested.- Returns:
True
if this cache contains a mapping for the specified keys.- Throws:
TransactionException
- If operation within transaction is failed.
-
containsKeysAsync
IgniteFuture<Boolean> containsKeysAsync(Set<? extends K> keys) throws TransactionException
Asynchronously determines if theCache
contains entries for the specified keys.- Parameters:
keys
- Key whose presence in this cache is to be tested.- Returns:
- a Future representing pending completion of the operation.
- Throws:
TransactionException
- If operation within transaction is failed.
-
put
@IgniteAsyncSupported void put(K key, V val) throws TransactionException
- Specified by:
put
in interfacejavax.cache.Cache<K,V>
- Throws:
TransactionException
- If operation within transaction is failed.
-
putAsync
IgniteFuture<Void> putAsync(K key, V val) throws TransactionException
Asynchronously associates the specified value with the specified key in the cache.If the
Cache
previously contained a mapping for the key, the old value is replaced by the specified value. (A cache c is said to contain a mapping for a key k if and only ifc.containsKey(k)
would return true.)- Parameters:
key
- Key.val
- Value.- Returns:
- a Future representing pending completion of the operation.
- Throws:
TransactionException
- If operation within transaction is failed.
-
getAndPut
@IgniteAsyncSupported V getAndPut(K key, V val) throws TransactionException
- Specified by:
getAndPut
in interfacejavax.cache.Cache<K,V>
- Throws:
TransactionException
- If operation within transaction is failed.
-
getAndPutAsync
IgniteFuture<V> getAndPutAsync(K key, V val) throws TransactionException
Asynchronously associates the specified value with the specified key in this cache, returning an existing value if one existed as the future result.If the cache previously contained a mapping for the key, the old value is replaced by the specified value. (A cache c is said to contain a mapping for a key k if and only if
c.containsKey(k)
would return true.)The previous value is returned as the future result, or future result is null if there was no value associated with the key previously.
- Parameters:
key
- Key.val
- Value.- Returns:
- a Future representing pending completion of the operation.
- Throws:
TransactionException
- If operation within transaction is failed.
-
putAll
@IgniteAsyncSupported void putAll(Map<? extends K,? extends V> map) throws TransactionException
Keys are locked in the order in which they appear in map. It is caller's responsibility to make sure keys always follow same order, such as by using
TreeMap
. Using unordered map, such asHashMap
, while calling this method in parallel will lead to deadlock.- Specified by:
putAll
in interfacejavax.cache.Cache<K,V>
- Throws:
TransactionException
- If operation within transaction is failed.
-
putAllAsync
IgniteFuture<Void> putAllAsync(Map<? extends K,? extends V> map) throws TransactionException
Asynchronously copies all of the entries from the specified map to theCache
.The effect of this call is equivalent to that of calling
putAsync(Object, Object)
putAsync(k, v)} on this cache once for each mapping from key k to value v in the specified map.The order in which the individual puts occur is undefined.
The behavior of this operation is undefined if entries in the cache corresponding to entries in the map are modified or removed while this operation is in progress. or if map is modified while the operation is in progress.
In Default Consistency mode, individual puts occur atomically but not the entire putAll. Listeners may observe individual updates.
Keys are locked in the order in which they appear in map. It is caller's responsibility to make sure keys always follow same order, such as by using
TreeMap
. Using unordered map, such asHashMap
, while calling this method in parallel will lead to deadlock.- Parameters:
map
- Map containing keys and values to put into the cache.- Returns:
- a Future representing pending completion of the operation.
- Throws:
TransactionException
- If operation within transaction is failed.
-
putIfAbsent
@IgniteAsyncSupported boolean putIfAbsent(K key, V val) throws TransactionException
For
CacheAtomicityMode.ATOMIC
return value on primary node crash may be incorrect because of the automatic retries. It is recommended to disable retries withwithNoRetries()
and manually restore primary-backup consistency in case of update failure.- Specified by:
putIfAbsent
in interfacejavax.cache.Cache<K,V>
- Throws:
TransactionException
- If operation within transaction is failed.
-
putIfAbsentAsync
IgniteFuture<Boolean> putIfAbsentAsync(K key, V val)
Asynchronously associates the specified key with the given value if it is not already associated with a value.For
CacheAtomicityMode.ATOMIC
return value on primary node crash may be incorrect because of the automatic retries. It is recommended to disable retries withwithNoRetries()
and manually restore primary-backup consistency in case of update failure.- Parameters:
key
- Key.val
- Value.- Returns:
- a Future representing pending completion of the operation.
- Throws:
TransactionTimeoutException
- If operation performs within transaction and timeout occurred.TransactionRollbackException
- If operation performs within transaction that automatically rolled back.TransactionHeuristicException
- If operation performs within transaction that entered an unknown state.
-
remove
@IgniteAsyncSupported boolean remove(K key) throws TransactionException
- Specified by:
remove
in interfacejavax.cache.Cache<K,V>
- Throws:
TransactionException
- If operation within transaction is failed.
-
removeAsync
IgniteFuture<Boolean> removeAsync(K key) throws TransactionException
Asynchronously removes the mapping for a key from this cache if it is present.More formally, if this cache contains a mapping from key k to value v such that
(key==null ? k==null : key.equals(k))
, that mapping is removed. (The cache can contain at most one such mapping.)A future result is true if this cache previously associated the key, or false if the cache contained no mapping for the key.
The cache will not contain a mapping for the specified key once the returned future is completed.
- Parameters:
key
- Key.- Returns:
- a Future representing pending completion of the operation.
- Throws:
TransactionException
- If operation within transaction is failed.
-
remove
@IgniteAsyncSupported boolean remove(K key, V oldVal) throws TransactionException
For
CacheAtomicityMode.ATOMIC
return value on primary node crash may be incorrect because of the automatic retries. It is recommended to disable retries withwithNoRetries()
and manually restore primary-backup consistency in case of update failure.- Specified by:
remove
in interfacejavax.cache.Cache<K,V>
- Throws:
TransactionException
- If operation within transaction is failed.
-
removeAsync
IgniteFuture<Boolean> removeAsync(K key, V oldVal) throws TransactionException
Asynchronously removes the mapping for a key only if currently mapped to the given value.For
CacheAtomicityMode.ATOMIC
return value on primary node crash may be incorrect because of the automatic retries. It is recommended to disable retries withwithNoRetries()
and manually restore primary-backup consistency in case of update failure.- Parameters:
key
- Key.oldVal
- Old value.- Returns:
- a Future representing pending completion of the operation.
- Throws:
TransactionException
- If operation within transaction is failed.
-
getAndRemove
@IgniteAsyncSupported V getAndRemove(K key) throws TransactionException
- Specified by:
getAndRemove
in interfacejavax.cache.Cache<K,V>
- Throws:
TransactionException
- If operation within transaction is failed.
-
getAndRemoveAsync
IgniteFuture<V> getAndRemoveAsync(K key) throws TransactionException
Asynchronously removes the entry for a key only if currently mapped to some value.- Parameters:
key
- Key.- Returns:
- a Future representing pending completion of the operation.
- Throws:
TransactionException
- If operation within transaction is failed.
-
replace
@IgniteAsyncSupported boolean replace(K key, V oldVal, V newVal) throws TransactionException
For
CacheAtomicityMode.ATOMIC
return value on primary node crash may be incorrect because of the automatic retries. It is recommended to disable retries withwithNoRetries()
and manually restore primary-backup consistency in case of update failure.- Specified by:
replace
in interfacejavax.cache.Cache<K,V>
- Throws:
TransactionException
- If operation within transaction is failed.
-
replaceAsync
IgniteFuture<Boolean> replaceAsync(K key, V oldVal, V newVal) throws TransactionException
Asynchronous version of thereplace(Object, Object, Object)
.For
CacheAtomicityMode.ATOMIC
return value on primary node crash may be incorrect because of the automatic retries. It is recommended to disable retries withwithNoRetries()
and manually restore primary-backup consistency in case of update failure.- Parameters:
key
- Key.oldVal
- Old value.newVal
- New value.- Returns:
- a Future representing pending completion of the operation.
- Throws:
TransactionException
- If operation within transaction is failed.
-
replace
@IgniteAsyncSupported boolean replace(K key, V val) throws TransactionException
- Specified by:
replace
in interfacejavax.cache.Cache<K,V>
- Throws:
TransactionException
- If operation within transaction is failed.
-
replaceAsync
IgniteFuture<Boolean> replaceAsync(K key, V val) throws TransactionException
Asynchronously replaces the entry for a key only if currently mapped to a given value.- Parameters:
key
- Key.val
- Value.- Returns:
- a Future representing pending completion of the operation.
- Throws:
TransactionException
- If operation within transaction is failed.
-
getAndReplace
@IgniteAsyncSupported V getAndReplace(K key, V val) throws TransactionException
- Specified by:
getAndReplace
in interfacejavax.cache.Cache<K,V>
- Throws:
TransactionException
- If operation within transaction is failed.
-
getAndReplaceAsync
IgniteFuture<V> getAndReplaceAsync(K key, V val)
Asynchronously replaces the value for a given key if and only if there is a value currently mapped by the key.- Parameters:
key
- Key.val
- Value.- Returns:
- a Future representing pending completion of the operation.
- Throws:
TransactionTimeoutException
- If operation performs within transaction and timeout occurred.TransactionRollbackException
- If operation performs within transaction that automatically rolled back.TransactionHeuristicException
- If operation performs within transaction that entered an unknown state.
-
removeAll
@IgniteAsyncSupported void removeAll(Set<? extends K> keys) throws TransactionException
Keys are locked in the order in which they appear in key set. It is caller's responsibility to make sure keys always follow same order, such as by using
TreeSet
. Using unordered map, such asHashSet
, while calling this method in parallel will lead to deadlock.- Specified by:
removeAll
in interfacejavax.cache.Cache<K,V>
- Throws:
TransactionException
- If operation within transaction is failed.
-
removeAllAsync
IgniteFuture<Void> removeAllAsync(Set<? extends K> keys) throws TransactionException
Asynchronously removes entries for the specified keys.The order in which the individual entries are removed is undefined.
For every entry in the key set, the following are called:
- any registered
CacheEntryRemovedListener
s - if the cache is a write-through cache, the
CacheWriter
CacheWriter
is not called.Keys are locked in the order in which they appear in key set. It is caller's responsibility to make sure keys always follow same order, such as by using
TreeSet
. Using unordered map, such asHashSet
, while calling this method in parallel will lead to deadlock.- Parameters:
keys
- Keys set.- Returns:
- a Future representing pending completion of the operation.
- Throws:
TransactionException
- If operation within transaction is failed.
- any registered
-
removeAll
@IgniteAsyncSupported void removeAll()
Removes all of the mappings from this cache.The order that the individual entries are removed is undefined.
For every mapping that exists the following are called:
- any registered
CacheEntryRemovedListener
s - if the cache is a write-through cache, the
CacheWriter
CacheWriter
is not called.This operation is not transactional. It calls broadcast closure that deletes all primary keys from remote nodes.
This is potentially an expensive operation as listeners are invoked. Use
clear()
to avoid this.- Specified by:
removeAll
in interfacejavax.cache.Cache<K,V>
- Throws:
IllegalStateException
- if the cache isCache.isClosed()
javax.cache.CacheException
- if there is a problem during the remove- See Also:
clear()
,CacheWriter.deleteAll(java.util.Collection<?>)
- any registered
-
removeAllAsync
IgniteFuture<Void> removeAllAsync()
Asynchronously removes all of the mappings from this cache.The order that the individual entries are removed is undefined.
For every mapping that exists the following are called:
- any registered
CacheEntryRemovedListener
s - if the cache is a write-through cache, the
CacheWriter
CacheWriter
is not called.This is potentially an expensive operation as listeners are invoked. Use
clearAsync()
to avoid this.- Returns:
- a Future representing pending completion of the operation.
- Throws:
IllegalStateException
- if the cache isCache.isClosed()
javax.cache.CacheException
- if there is a problem during the remove- See Also:
clearAsync()
,CacheWriter.deleteAll(java.util.Collection<?>)
- any registered
-
clear
@IgniteAsyncSupported void clear()
Clears the contents of the cache, without notifying listeners orCacheWriter
s. Entries are cleared only if they are not currently locked, and are not participating in a transaction. This operation is not transactional. It calls broadcast closure that deletes all primary keys from remote nodes.- Specified by:
clear
in interfacejavax.cache.Cache<K,V>
- Throws:
IllegalStateException
- if the cache isCache.isClosed()
.javax.cache.CacheException
- if there is a problem during the clear.
-
clearAsync
IgniteFuture<Void> clearAsync()
Asynchronously clears the contents of the cache, without notifying listeners orCacheWriter
s. This operation is not transactional. It calls broadcast closure that deletes all primary keys from remote nodes.- Returns:
- a Future representing pending completion of the operation.
-
clear
@IgniteAsyncSupported void clear(K key)
Clears entry from the cache and swap storage, without notifying listeners orCacheWriter
s. Entry is cleared only if it is not currently locked, and is not participating in a transaction. This operation is not transactional. It calls broadcast closure that deletes all primary keys from remote nodes.- Parameters:
key
- Key to clear.- Throws:
IllegalStateException
- if the cache isCache.isClosed()
javax.cache.CacheException
- if there is a problem during the clear
-
clearAsync
IgniteFuture<Void> clearAsync(K key)
Asynchronously clears entry from the cache and swap storage, without notifying listeners orCacheWriter
s. Entry is cleared only if it is not currently locked, and is not participating in a transaction. This operation is not transactional. It calls broadcast closure that deletes all primary keys from remote nodes.- Parameters:
key
- Key to clear.- Returns:
- a Future representing pending completion of the operation.
- Throws:
IllegalStateException
- if the cache isCache.isClosed()
javax.cache.CacheException
- if there is a problem during the clear
-
clearAll
@IgniteAsyncSupported void clearAll(Set<? extends K> keys)
Clears entries from the cache and swap storage, without notifying listeners orCacheWriter
s. Entry is cleared only if it is not currently locked, and is not participating in a transaction. This operation is not transactional. It calls broadcast closure that deletes all primary keys from remote nodes.- Parameters:
keys
- Keys to clear.- Throws:
IllegalStateException
- if the cache isCache.isClosed()
javax.cache.CacheException
- if there is a problem during the clear
-
clearAllAsync
IgniteFuture<Void> clearAllAsync(Set<? extends K> keys)
Asynchronously clears entries from the cache and swap storage, without notifying listeners orCacheWriter
s. Entry is cleared only if it is not currently locked, and is not participating in a transaction. This operation is not transactional. It calls broadcast closure that deletes all primary keys from remote nodes.- Parameters:
keys
- Keys to clear.- Returns:
- a Future representing pending completion of the operation.
- Throws:
IllegalStateException
- if the cache isCache.isClosed()
javax.cache.CacheException
- if there is a problem during the clear
-
localClear
void localClear(K key)
Clears entry from the cache and swap storage, without notifying listeners orCacheWriter
s. Entry is cleared only if it is not currently locked, and is not participating in a transaction. This operation is not transactional. It calls broadcast closure that deletes all primary keys from remote nodes. Note that this operation is local as it merely clears an entry from local cache, it does not remove entries from remote caches.- Parameters:
key
- Key to clear.
-
localClearAll
void localClearAll(Set<? extends K> keys)
Clears entries from the cache and swap storage, without notifying listeners orCacheWriter
s. Entry is cleared only if it is not currently locked, and is not participating in a transaction. This operation is not transactional. It calls broadcast closure that deletes all primary keys from remote nodes. Note that this operation is local as it merely clears an entry from local cache, it does not remove entries from remote caches.- Parameters:
keys
- Keys to clear.
-
invoke
@IgniteAsyncSupported <T> T invoke(K key, javax.cache.processor.EntryProcessor<K,V,T> entryProcessor, Object... arguments) throws TransactionException
Please refer to documentation for
CacheAtomicityMode.ATOMIC
for information on system behavior in crash scenarios for atomic caches.- Specified by:
invoke
in interfacejavax.cache.Cache<K,V>
- Throws:
TransactionException
- If operation within transaction is failed.
-
invokeAsync
<T> IgniteFuture<T> invokeAsync(K key, javax.cache.processor.EntryProcessor<K,V,T> entryProcessor, Object... arguments) throws TransactionException
Asynchronously invokes anEntryProcessor
against theCache.Entry
specified by the provided key. If anCache.Entry
does not exist for the specified key, an attempt is made to load it (if a loader is configured) or a surrogateCache.Entry
, consisting of the key with a null value is used instead.Please refer to documentation for
CacheAtomicityMode.ATOMIC
for information on system behavior in crash scenarios for atomic caches.- Type Parameters:
T
- Type of the cache entry processing result.- Parameters:
key
- The key to the entry.entryProcessor
- TheEntryProcessor
to invoke.arguments
- Additional arguments to pass to theEntryProcessor
.- Returns:
- a Future representing pending completion of the operation.
- Throws:
TransactionException
- If operation within transaction is failed.
-
invoke
@IgniteAsyncSupported <T> T invoke(K key, CacheEntryProcessor<K,V,T> entryProcessor, Object... arguments) throws TransactionException
Invokes anCacheEntryProcessor
against theCache.Entry
specified by the provided key. If anCache.Entry
does not exist for the specified key, an attempt is made to load it (if a loader is configured) or a surrogateCache.Entry
, consisting of the key with a null value is used instead.An instance of entry processor must be stateless as it may be invoked multiple times on primary and backup nodes in the cache. It is guaranteed that the value passed to the entry processor will be always the same.
Please refer to documentation for
CacheAtomicityMode.ATOMIC
for information on system behavior in crash scenarios for atomic caches.- Type Parameters:
T
- Type of the cache entry processing result.- Parameters:
key
- The key to the entry.entryProcessor
- TheCacheEntryProcessor
to invoke.arguments
- Additional arguments to pass to theCacheEntryProcessor
.- Returns:
- The result of the processing, if any, defined by the
CacheEntryProcessor
implementation. - Throws:
NullPointerException
- If key orCacheEntryProcessor
is nullIllegalStateException
- If the cache isCache.isClosed()
ClassCastException
- If the implementation is configured to perform runtime-type-checking, and the key or value types are incompatible with those that have been configured for theCache
.javax.cache.processor.EntryProcessorException
- If an exception is thrown by theCacheEntryProcessor
, a Caching Implementation must wrap anyException
thrown wrapped in anEntryProcessorException
.TransactionException
- If operation within transaction is failed.- See Also:
CacheEntryProcessor
-
invokeAsync
<T> IgniteFuture<T> invokeAsync(K key, CacheEntryProcessor<K,V,T> entryProcessor, Object... arguments) throws TransactionException
Asynchronously invokes anCacheEntryProcessor
against theCache.Entry
specified by the provided key. If anCache.Entry
does not exist for the specified key, an attempt is made to load it (if a loader is configured) or a surrogateCache.Entry
, consisting of the key with a null value is used instead.An instance of entry processor must be stateless as it may be invoked multiple times on primary and backup nodes in the cache. It is guaranteed that the value passed to the entry processor will be always the same.
- Type Parameters:
T
- Type of the cache entry processing result.- Parameters:
key
- The key to the entry.entryProcessor
- TheCacheEntryProcessor
to invoke.arguments
- Additional arguments to pass to theCacheEntryProcessor
.- Returns:
- a Future representing pending completion of the operation.
- Throws:
NullPointerException
- If key orCacheEntryProcessor
is nullIllegalStateException
- If the cache isCache.isClosed()
ClassCastException
- If the implementation is configured to perform runtime-type-checking, and the key or value types are incompatible with those that have been configured for theCache
.javax.cache.processor.EntryProcessorException
- If an exception is thrown by theCacheEntryProcessor
, a Caching Implementation must wrap anyException
thrown wrapped in anEntryProcessorException
.TransactionException
- If operation within transaction is failed.- See Also:
CacheEntryProcessor
-
invokeAll
@IgniteAsyncSupported <T> Map<K,javax.cache.processor.EntryProcessorResult<T>> invokeAll(Set<? extends K> keys, javax.cache.processor.EntryProcessor<K,V,T> entryProcessor, Object... args) throws TransactionException
Please refer to documentation for
CacheAtomicityMode.ATOMIC
for information on system behavior in crash scenarios for atomic caches.Keys are locked in the order in which they appear in key set. It is caller's responsibility to make sure keys always follow same order, such as by using
TreeSet
. Using unordered map, such asHashSet
, while calling this method in parallel will lead to deadlock.- Specified by:
invokeAll
in interfacejavax.cache.Cache<K,V>
- Throws:
TransactionException
- If operation within transaction is failed.
-
invokeAllAsync
<T> IgniteFuture<Map<K,javax.cache.processor.EntryProcessorResult<T>>> invokeAllAsync(Set<? extends K> keys, javax.cache.processor.EntryProcessor<K,V,T> entryProcessor, Object... args) throws TransactionException
Asynchronously invokes anEntryProcessor
against the set ofCache.Entry
s specified by the set of keys.If an
Cache.Entry
does not exist for the specified key, an attempt is made to load it (if a loader is configured) or a surrogateCache.Entry
, consisting of the key and a value of null is provided.The order that the entries for the keys are processed is undefined. Implementations may choose to process the entries in any order, including concurrently. Furthermore there is no guarantee implementations will use the same
EntryProcessor
instance to process each entry, as the case may be in a non-local cache topology.The result of executing the
EntryProcessor
is returned in the future as aMap
ofEntryProcessorResult
s, one result per key. Should theEntryProcessor
or Caching implementation throw an exception, the exception is wrapped and re-thrown when a call toEntryProcessorResult.get()
is made.Please refer to documentation for
CacheAtomicityMode.ATOMIC
for information on system behavior in crash scenarios for atomic caches.Keys are locked in the order in which they appear in key set. It is caller's responsibility to make sure keys always follow same order, such as by using
TreeSet
. Using unordered map, such asHashSet
, while calling this method in parallel will lead to deadlock.- Type Parameters:
T
- Type of the cache entry processing result.- Parameters:
keys
- The set of keys.entryProcessor
- TheEntryProcessor
to invoke.args
- Additional arguments to pass to theEntryProcessor
.- Returns:
- a Future representing pending completion of the operation.
- Throws:
TransactionException
- If operation within transaction is failed.
-
invokeAll
@IgniteAsyncSupported <T> Map<K,javax.cache.processor.EntryProcessorResult<T>> invokeAll(Set<? extends K> keys, CacheEntryProcessor<K,V,T> entryProcessor, Object... args) throws TransactionException
Invokes anCacheEntryProcessor
against the set ofCache.Entry
s specified by the set of keys.If an
Cache.Entry
does not exist for the specified key, an attempt is made to load it (if a loader is configured) or a surrogateCache.Entry
, consisting of the key and a value of null is provided.The order that the entries for the keys are processed is undefined. Implementations may choose to process the entries in any order, including concurrently. Furthermore there is no guarantee implementations will use the same
CacheEntryProcessor
instance to process each entry, as the case may be in a non-local cache topology.The result of executing the
CacheEntryProcessor
is returned as aMap
ofEntryProcessorResult
s, one result per key. Should theCacheEntryProcessor
or Caching implementation throw an exception, the exception is wrapped and re-thrown when a call toEntryProcessorResult.get()
is made.An instance of entry processor must be stateless as it may be invoked multiple times on primary and backup nodes in the cache. It is guaranteed that the value passed to the entry processor will be always the same.
Keys are locked in the order in which they appear in key set. It is caller's responsibility to make sure keys always follow same order, such as by using
TreeSet
. Using unordered map, such asHashSet
, while calling this method in parallel will lead to deadlock.- Type Parameters:
T
- Type of the cache entry processing result.- Parameters:
keys
- The set of keys for entries to process.entryProcessor
- TheCacheEntryProcessor
to invoke.args
- Additional arguments to pass to theCacheEntryProcessor
.- Returns:
- The map of
EntryProcessorResult
s of the processing per key, if any, defined by theCacheEntryProcessor
implementation. No mappings will be returned forCacheEntryProcessor
s that return anull
value for a key. - Throws:
NullPointerException
- If keys orCacheEntryProcessor
are {#code null}.IllegalStateException
- If the cache isCache.isClosed()
.ClassCastException
- If the implementation is configured to perform runtime-type-checking, and the key or value types are incompatible with those that have been configured for theCache
.TransactionException
- If operation within transaction is failed.- See Also:
CacheEntryProcessor
-
invokeAllAsync
<T> IgniteFuture<Map<K,javax.cache.processor.EntryProcessorResult<T>>> invokeAllAsync(Set<? extends K> keys, CacheEntryProcessor<K,V,T> entryProcessor, Object... args) throws TransactionException
Asynchronously invokes anCacheEntryProcessor
against the set ofCache.Entry
s specified by the set of keys.If an
Cache.Entry
does not exist for the specified key, an attempt is made to load it (if a loader is configured) or a surrogateCache.Entry
, consisting of the key and a value of null is provided.The order that the entries for the keys are processed is undefined. Implementations may choose to process the entries in any order, including concurrently. Furthermore there is no guarantee implementations will use the same
CacheEntryProcessor
instance to process each entry, as the case may be in a non-local cache topology.The result of executing the
CacheEntryProcessor
is returned in the future as aMap
ofEntryProcessorResult
s, one result per key. Should theCacheEntryProcessor
or Caching implementation throw an exception, the exception is wrapped and re-thrown when a call toEntryProcessorResult.get()
is made.An instance of entry processor must be stateless as it may be invoked multiple times on primary and backup nodes in the cache. It is guaranteed that the value passed to the entry processor will be always the same.
Keys are locked in the order in which they appear in key set. It is caller's responsibility to make sure keys always follow same order, such as by using
TreeSet
. Using unordered map, such asHashSet
, while calling this method in parallel will lead to deadlock.- Type Parameters:
T
- Type of the cache entry processing result.- Parameters:
keys
- The set of keys for entries to process.entryProcessor
- TheCacheEntryProcessor
to invoke.args
- Additional arguments to pass to theCacheEntryProcessor
.- Returns:
- a Future representing pending completion of the operation.
- Throws:
NullPointerException
- If keys orCacheEntryProcessor
are {#code null}.IllegalStateException
- If the cache isCache.isClosed()
.ClassCastException
- If the implementation is configured to perform runtime-type-checking, and the key or value types are incompatible with those that have been configured for theCache
.TransactionException
- If operation within transaction is failed.- See Also:
CacheEntryProcessor
-
close
void close()
Closes this cache instance.For local cache equivalent to
destroy()
. For distributed caches, if called on clients, stops client cache, if called on a server node, just closes this cache instance and does not destroy cache data.After cache instance is closed another
IgniteCache
instance for the same cache can be created usingIgnite.cache(String)
method.
-
destroy
void destroy()
Completely deletes the cache with all its data from the system on all cluster nodes.
-
rebalance
@Deprecated IgniteFuture<Boolean> rebalance()
Deprecated.Use baseline topology feature instead. Please, be aware this API will be removed in the next releases.This cache node to re-balance its partitions. This method is usually used whenCacheConfiguration.getRebalanceDelay()
configuration parameter has non-zero value. When many nodes are started or stopped almost concurrently, it is more efficient to delay rebalancing until the node topology is stable to make sure that no redundant re-partitioning happens.In case of
CacheMode.PARTITIONED
caches, for better efficiency user should usually make sure that new nodes get placed on the same place of consistent hash ring as the left nodes, and that nodes are restarted beforerebalanceDelay
expires. To place nodes on the same place in consistent hash ring, useIgniteConfiguration.setConsistentId(Serializable)
to make sure that a node maps to the same hash ID if re-started.See
CacheConfiguration.getRebalanceDelay()
for more information on how to configure rebalance re-partition delay.- Returns:
- Future that will be completed when rebalancing is finished. Future.get() returns
true
when rebalance was successfully finished.
-
indexReadyFuture
IgniteFuture<?> indexReadyFuture()
Returns future that will be completed when all indexes for this cache are ready to use.- Returns:
- Future.
-
metrics
CacheMetrics metrics()
Gets whole cluster snapshot metrics (statistics) for this cache.- Returns:
- Cache metrics.
-
metrics
CacheMetrics metrics(ClusterGroup grp)
Gets cluster group snapshot metrics for caches in cluster group.- Parameters:
grp
- Cluster group.- Returns:
- Cache metrics.
-
localMetrics
CacheMetrics localMetrics()
Gets local snapshot metrics (statistics) for this cache.- Returns:
- Cache metrics.
-
lostPartitions
Collection<Integer> lostPartitions()
Gets a collection of lost partition IDs. This method provides a facility for fine-tuned handling of lost partitions. Once all lost partitions are considered recovered (for example, after the previously failed primary and backup nodes, that stored partition data in Ignite persistence, are booted)Ignite.resetLostPartitions(Collection)
can used in order to clearlost
flag making all partitions fully operational.- Returns:
- Lost partitions.
- See Also:
PartitionLossPolicy
,EventType.EVT_CACHE_REBALANCE_PART_DATA_LOST
,Ignite.resetLostPartitions(Collection)
-
enableStatistics
void enableStatistics(boolean enabled)
Sets statistics enabled flag cluster wide for this cache.- Parameters:
enabled
- Statistics enabled flag.
-
clearStatistics
void clearStatistics()
Clear cluster statistics for this cache.
-
preloadPartition
void preloadPartition(int partition)
Efficiently preloads cache primary partition into page memory.This is useful for fast iteration over cache partition data if persistence is enabled and the data is "cold".
Preload will reduce available amount of page memory for subsequent operations and may lead to earlier page replacement.
This method is irrelevant for in-memory caches. Calling this method on an in-memory cache will result in exception.
- Parameters:
partition
- Partition.
-
preloadPartitionAsync
IgniteFuture<Void> preloadPartitionAsync(int partition)
Efficiently preloads cache partition into page memory.This is useful for fast iteration over cache partition data if persistence is enabled and the data is "cold".
Preload will reduce available amount of page memory for subsequent operations and may lead to earlier page replacement.
This method is irrelevant for in-memory caches. Calling this method on an in-memory cache will result in exception.
- Parameters:
partition
- Partition.- Returns:
- A future representing pending completion of the partition preloading.
-
localPreloadPartition
boolean localPreloadPartition(int partition)
Efficiently preloads cache partition into page memory if it exists on the local node.This is useful for fast iteration over cache partition data if persistence is enabled and the data is "cold".
Preload will reduce available amount of page memory for subsequent operations and may lead to earlier page replacement.
This method is irrelevant for in-memory caches. Calling this method on an in-memory cache will result in exception.
- Parameters:
partition
- Partition.- Returns:
True
if partition was preloaded,false
if it doesn't belong to local node.
-
-