K
- Cache key type.V
- Cache value type.public interface GridCache<K,V> extends org.apache.ignite.internal.processors.cache.CacheProjection<K,V>
org.apache.ignite.Ignite#cache(String)
method.
CacheProjection
API which contains vast majority of cache functionality
and documentation. In addition to CacheProjection
functionality this API provides:
'loadCache(..)'
methods to load cache either synchronously or asynchronously.
These methods don't specify any keys to load, and leave it to the underlying storage to load cache
data based on the optionally passed in arguments.
affinity()
provides CacheAffinityFunction
service for information on
data partitioning and mapping keys to grid nodes responsible for caching those keys.
'tx{Un}Synchronize(..)'
witch allow to get notifications for transaction state changes.
This feature is very useful when integrating cache transactions with some other in-house transactions.
metrics()
to provide metrics for the whole cache.configuration()
to provide cache configuration bean.Modifier and Type | Method and Description |
---|---|
CacheAffinity<K> |
affinity()
Gets affinity service to provide information about data partitioning
and distribution.
|
CacheConfiguration |
configuration()
Gets configuration bean for this cache.
|
org.apache.ignite.internal.IgniteInternalFuture<?> |
forceRepartition()
Forces this cache node to re-balance its partitions.
|
void |
loadCache(IgniteBiPredicate<K,V> p,
long ttl,
Object... args)
Delegates to
CacheStore.loadCache(org.apache.ignite.lang.IgniteBiInClosure,Object...) method
to load state from the underlying persistent storage. |
org.apache.ignite.internal.IgniteInternalFuture<?> |
loadCacheAsync(IgniteBiPredicate<K,V> p,
long ttl,
Object... args)
Asynchronously delegates to
CacheStore.loadCache(org.apache.ignite.lang.IgniteBiInClosure, Object...) method
to reload state from the underlying persistent storage. |
CacheMetrics |
metrics()
Gets metrics (statistics) for this cache.
|
CacheMetricsMXBean |
mxBean()
Gets metrics (statistics) for this cache.
|
long |
offHeapAllocatedSize()
Gets memory size allocated in off-heap.
|
long |
offHeapEntriesCount()
Gets number of cache entries stored in off-heap memory.
|
Iterator<Map.Entry<K,V>> |
offHeapIterator()
Gets iterator over keys and values belonging to this cache off-heap memory on local node.
|
long |
overflowSize()
Gets size (in bytes) of all entries swapped to disk.
|
javax.cache.Cache.Entry<K,V> |
randomEntry()
Gets a random entry out of cache.
|
Iterator<Map.Entry<K,V>> |
swapIterator()
Gets iterator over keys and values belonging to this cache swap space on local node.
|
long |
swapKeys()
Gets number of swap entries (keys).
|
long |
swapSize()
Gets size in bytes for swap space.
|
Collection<TransactionSynchronization> |
txSynchronizations()
Gets registered transaction synchronizations.
|
void |
txSynchronize(TransactionSynchronization syncs)
Registers transactions synchronizations for all transactions started by this cache.
|
void |
txUnsynchronize(TransactionSynchronization syncs)
Removes transaction synchronizations.
|
cache, clear, clear, clearAsync, clearLocally, clearLocally, compact, compactAll, containsKey, containsKeyAsync, containsKeys, containsKeysAsync, containsValue, entry, entrySet, entrySet, evict, evictAll, evictAll, flags, flagsOff, flagsOn, forAll, forEach, get, getAll, getAllAsync, getAsync, globalPrimarySize, globalSize, gridProjection, isEmpty, isLocked, isLockedByThread, keepPortable, keySet, keySet, localEntries, localPeek, localSize, lock, lockAll, lockAllAsync, lockAsync, name, nearSize, peek, peek, primaryEntrySet, primaryKeySet, primarySize, primaryValues, projection, projection, projection, promote, promoteAll, put, putAll, putAllAsync, putAsync, putIfAbsent, putIfAbsentAsync, putx, putxAsync, putxIfAbsent, putxIfAbsentAsync, queries, reload, reloadAll, reloadAll, reloadAllAsync, reloadAllAsync, reloadAsync, remove, remove, removeAll, removeAll, removeAllAsync, removeAllAsync, removeAllAsync, removeAsync, removeAsync, removex, removexAsync, replace, replace, replaceAsync, replaceAsync, replacex, replacexAsync, size, size, sizeAsync, toMap, tx, txStart, txStart, txStart, txStartEx, unlock, unlockAll, values
CacheConfiguration configuration()
void txSynchronize(@Nullable TransactionSynchronization syncs)
syncs
- Transaction synchronizations to register.void txUnsynchronize(@Nullable TransactionSynchronization syncs)
syncs
- Transactions synchronizations to remove.txSynchronize(TransactionSynchronization)
Collection<TransactionSynchronization> txSynchronizations()
txSynchronize(TransactionSynchronization)
CacheAffinity<K> affinity()
CacheMetrics metrics()
CacheMetricsMXBean mxBean()
long overflowSize() throws IgniteCheckedException
IgniteCheckedException
- In case of error.long offHeapEntriesCount()
long offHeapAllocatedSize()
long swapSize() throws IgniteCheckedException
IgniteCheckedException
- If failed.long swapKeys() throws IgniteCheckedException
IgniteCheckedException
- If failed.Iterator<Map.Entry<K,V>> swapIterator() throws IgniteCheckedException
Returned iterator supports remove
operation which delegates to
CacheProjection.removex(Object, org.apache.ignite.lang.IgnitePredicate[])
method.
CacheFlag.SKIP_SWAP
.IgniteCheckedException
- If failed.CacheProjection.promote(Object)
Iterator<Map.Entry<K,V>> offHeapIterator() throws IgniteCheckedException
Returned iterator supports remove
operation which delegates to
CacheProjection.removex(Object, org.apache.ignite.lang.IgnitePredicate[])
method.
IgniteCheckedException
- If failed.void loadCache(@Nullable IgniteBiPredicate<K,V> p, long ttl, @Nullable Object... args) throws IgniteCheckedException
CacheStore.loadCache(org.apache.ignite.lang.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 returns
true
, will be stored in cache. If predicate is null
, 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.
p
- Optional predicate (may be null
). If provided, will be used to
filter values to be put into cache.ttl
- Time to live for loaded entries (0
for infinity).args
- Optional user arguments to be passed into
CacheStore.loadCache(org.apache.ignite.lang.IgniteBiInClosure, Object...)
method.IgniteCheckedException
- If loading failed.org.apache.ignite.internal.IgniteInternalFuture<?> loadCacheAsync(@Nullable IgniteBiPredicate<K,V> p, long ttl, @Nullable Object... args)
CacheStore.loadCache(org.apache.ignite.lang.IgniteBiInClosure, Object...)
method
to reload state from the underlying persistent storage. The reloaded values
will then be given to the optionally passed in predicate, and if the predicate returns
true
, will be stored in cache. If predicate is null
, then
all reloaded 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.
p
- Optional predicate (may be null
). If provided, will be used to
filter values to be put into cache.ttl
- Time to live for loaded entries (0
for infinity).args
- Optional user arguments to be passed into
CacheStore.loadCache(org.apache.ignite.lang.IgniteBiInClosure,Object...)
method.@Nullable javax.cache.Cache.Entry<K,V> randomEntry()
O(S * N/64)where
N
is the size of internal hash
table and S
is the number of hash table buckets to sample, which is 5
by default. However, if the table is pretty dense, with density factor of N/64
,
which is true for near fully populated caches, this method will generally perform significantly
faster with complexity of O(S) where S = 5
.
Note that this method is not available on CacheProjection
API since it is
impossible (or very hard) to deterministically return a number value when pre-filtering
and post-filtering is involved (e.g. projection level predicate filters).
null
if cache is empty.org.apache.ignite.internal.IgniteInternalFuture<?> forceRepartition()
CacheConfiguration.getPreloadPartitionedDelay()
configuration parameter has non-zero value.
When many nodes are started or stopped almost concurrently, it is more efficient to delay
preloading until the node topology is stable to make sure that no redundant re-partitioning
happens.
In case ofCacheMode.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 before
preloadDelay
expires. To place nodes
on the same place in consistent hash ring, use
CacheConsistentHashAffinityFunction.setHashIdResolver(org.apache.ignite.cache.affinity.CacheAffinityNodeHashResolver)
to make sure that
a node maps to the same hash ID if re-started.
See CacheConfiguration.getPreloadPartitionedDelay()
for more information on how to configure
preload re-partition delay.
Follow @ApacheIgnite
Apache Ignite Fabric : ver. 1.0.0-RC1 Release Date : February 16 2015