org.apache.ignite.internal.processors.cache.local

## Class GridLocalCache<K,V>

- java.lang.Object
- - org.apache.ignite.internal.processors.cache.GridCacheAdapter<K,V>
  - - org.apache.ignite.internal.processors.cache.local.GridLocalCache<K,V>

All Implemented Interfaces:
  Externalizable, Serializable, Iterable<javax.cache.Cache.Entry<K,V>>, GridCache<K,V>, CacheProjection<K,V>, GridCacheProjectionEx<K,V>

    public class GridLocalCache<K,V>
    extends GridCacheAdapter<K,V>

Local cache implementation.

See Also:
  Serialized Form

### Nested Class Summary

### Nested classes/interfaces inherited from class org.apache.ignite.internal.processors.cache.GridCacheAdapter

`GridCacheAdapter.AsyncOp<T>, GridCacheAdapter.CacheExpiryPolicy, GridCacheAdapter.FutureHolder, GridCacheAdapter.UpdateGetTimeStatClosure<T>, GridCacheAdapter.UpdatePutAndGetTimeStatClosure<T>, GridCacheAdapter.UpdatePutTimeStatClosure<T>, GridCacheAdapter.UpdateRemoveTimeStatClosure<T>, GridCacheAdapter.UpdateTimeStatClosure<T>`

### Field Summary

### Fields inherited from class org.apache.ignite.internal.processors.cache.GridCacheAdapter

`cacheCfg, CLEAR_ALL_SPLIT_THRESHOLD, ctx, gridCfg, keyCheck, lastFut, locNodeId, log, map, metrics, mxBean`

### Constructor Summary

Constructors
Constructor and Description
`GridLocalCache()` Empty constructor required by `Externalizable`.
`GridLocalCache(GridCacheContext<K,V> ctx)`

### Method Summary

Methods
`protected void` `init()` Post constructor initialization for subclasses.
`boolean` `isLocal()`
`IgniteInternalFuture<Boolean>` `lockAllAsync(Collection<? extends K> keys, long timeout, IgnitePredicate<javax.cache.Cache.Entry<K,V>>[] filter)` All or nothing synchronous lock for passed in keys.
`IgniteInternalFuture<Boolean>` `lockAllAsync(Collection<? extends K> keys, long timeout, IgniteTxLocalEx<K,V> tx, IgnitePredicate<javax.cache.Cache.Entry<K,V>>[] filter)`
`void` `onDeferredDelete(GridCacheEntryEx<K,V> entry, GridCacheVersion ver)`
`GridCachePreloader<K,V>` `preloader()`
`void` `removeAll()` Removes mappings from cache for entries for which the optionally passed in filters do pass.
`IgniteInternalFuture<?>` `removeAllAsync()`
`IgniteInternalFuture<Boolean>` `txLockAsync(Collection<? extends K> keys, long timeout, IgniteTxLocalEx<K,V> tx, boolean isRead, boolean retval, TransactionIsolation isolation, boolean invalidate, long accessTtl, IgnitePredicate<javax.cache.Cache.Entry<K,V>>[] filter)`
`void` `unlockAll(Collection<? extends K> keys, IgnitePredicate<javax.cache.Cache.Entry<K,V>>[] filter)` Unlocks given keys only if current thread owns the locks.

### Methods inherited from class org.apache.ignite.internal.processors.cache.GridCacheAdapter

`affinity, allEntries, asyncOp, asyncOpAcquire, asyncOpRelease, awaitLastFut, cache, checkJta, clear, clear, clearAsync, clearLocally, clearLocally, clearLocally, clearLocally0, clearLocally0, commitTxAsync, compact, compact, compactAll, compactAll, configuration, containsKey, containsKeyAsync, containsKeys, containsKeysAsync, containsValue, context, entries, entry, entryEx, entryEx, entryEx, entryExSafe, entrySet, entrySet, entrySet, entrySet, entrySetx, evict, evict, evictAll, evictAll, evictAll, expiry, expiryPolicy, flags, flagsOff, flagsOn, forAll, forceRepartition, forEach, forSubjectId, get, get, get, getAll, getAll, getAllAsync, getAllAsync, getAllAsync, getAllAsync, getAllOutTx, getAllOutTxAsync, getAsync, getAsync, getForcePrimary, getForcePrimaryAsync, globalPrimarySize, globalSize, gridProjection, igfsDataSpaceMax, igfsDataSpaceUsed, igniteIterator, invoke, invokeAll, invokeAll, invokeAllAsync, invokeAllAsync, invokeAsync, isColocated, isDht, isDhtAtomic, isEmpty, isIgfsDataCache, isLocked, isLockedByThread, isMongoDataCache, isMongoMetaCache, isNear, iterator, iterator, keepPortable, keepPortable0, keySet, keySet, loadAll, loadCache, loadCacheAsync, localEntries, localLoad, localPeek, localSize, lock, lockAll, lockAsync, log, map, metrics, metrics0, mxBean, name, nearSize, offHeapAllocatedSize, offHeapEntriesCount, offHeapIterator, onIgfsDataSizeChanged, onKernalStart, onKernalStop, onUndeploy, overflowSize, peek, peek, peek, peek0, peek0, peek0, peekAll, peekAll0, peekAll0, peekEx, predicate, primaryEntrySet, primaryEntrySet, primaryEntrySetx, primaryKeySet, primaryKeySet, primarySize, primaryValues, primaryValues, printMemoryStats, projection, projection, projection, promote, promote, promoteAll, put, put, putAll, putAllAsync, putAllDr, putAllDrAsync, putAsync, putAsync, putIfAbsent, putIfAbsentAsync, putx, putx, putxAsync, putxAsync, putxIfAbsent, putxIfAbsentAsync, queries, randomEntry, readExternal, readResolve, readThroughAllAsync, reload, reloadAll, reloadAll, reloadAll, reloadAllAsync, reloadAllAsync, reloadAllAsync, reloadAsync, remove, remove, remove, removeAll, removeAllAsync, removeAllAsync, removeAllDr, removeAllDrAsync, removeAsync, removeAsync, removeAsync, removeEntry, removeIfObsolete, removex, removex, removex, removexAsync, removexAsync, removexAsync, replace, replace, replaceAsync, replaceAsync, replacex, replacex, replacexAsync, replacexAsync, saveFuture, size, size, sizeAsync, splitClearLocally, start, startInfo, stop, stopInfo, swapIterator, swapKeys, swapSize, toMap, toString, tx, txStart, txStart, txStart, txStartEx, txSynchronizations, txSynchronize, txUnsynchronize, unlock, validateCacheKey, validateCacheKeys, values, values, withExpiryPolicy, writeExternal`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### Constructor Detail

#### GridLocalCache

    public GridLocalCache()

Empty constructor required by `Externalizable`.

#### GridLocalCache

    public GridLocalCache(GridCacheContext<K,V> ctx)

Parameters:
  `ctx` - Cache registry.

### Method Detail

#### isLocal

    public boolean isLocal()

Overrides:
  `isLocal` in class `GridCacheAdapter<K,V>`
Returns:
  `True` if cache is local.

#### preloader

    public GridCachePreloader<K,V> preloader()

Specified by:
  `preloader` in class `GridCacheAdapter<K,V>`
Returns:
  Preloader.

#### init

    protected void init()

Post constructor initialization for subclasses.

Overrides:
  `init` in class `GridCacheAdapter<K,V>`

#### txLockAsync

    public IgniteInternalFuture<Boolean> txLockAsync(Collection<? extends K> keys,
                                            long timeout,
                                            IgniteTxLocalEx<K,V> tx,
                                            boolean isRead,
                                            boolean retval,
                                            TransactionIsolation isolation,
                                            boolean invalidate,
                                            long accessTtl,
                                            IgnitePredicate<javax.cache.Cache.Entry<K,V>>[] filter)

Specified by:
  `txLockAsync` in class `GridCacheAdapter<K,V>`
Parameters:
  `keys` - Keys to lock.
  `timeout` - Lock timeout.
  `tx` - Transaction.
  `isRead` - `True` for read operations.
  `retval` - Flag to return value.
  `isolation` - Transaction isolation.
  `invalidate` - Invalidate flag.
  `accessTtl` - TTL for read operation.
  `filter` - Optional filter.
Returns:
  Locks future.

#### lockAllAsync

    public IgniteInternalFuture<Boolean> lockAllAsync(Collection<? extends K> keys,
                                             long timeout,
                                             IgnitePredicate<javax.cache.Cache.Entry<K,V>>[] filter)

All or nothing synchronous lock for passed in keys. This method together with filter check will be executed as one atomic operation. If at least one filter validation failed, no locks will be acquired.

## Transactions

Locks are not transactional and should not be used from within transactions. If you do need explicit locking within transaction, then you should use `TransactionConcurrency.PESSIMISTIC` concurrency control for transaction which will acquire explicit locks for relevant cache operations.

## Cache Flags

This method is not available if any of the following flags are set on projection: `CacheFlag.LOCAL`, `CacheFlag.READ`.

Parameters:
  `keys` - Keys to lock.
  `timeout` - Timeout in milliseconds to wait for lock to be acquired (`'0'` for no expiration).
  `filter` - Optional filter that needs to atomically pass in order for the locks to be acquired.
Returns:
  Future for the collection of locks. The future will return `true` if all filters passed and locks were acquired before timeout has expired, `false` otherwise.

#### lockAllAsync

    public IgniteInternalFuture<Boolean> lockAllAsync(Collection<? extends K> keys,
                                             long timeout,
                                             @Nullable
                                             IgniteTxLocalEx<K,V> tx,
                                             IgnitePredicate<javax.cache.Cache.Entry<K,V>>[] filter)

Parameters:
  `keys` - Keys.
  `timeout` - Timeout.
  `tx` - Transaction.
  `filter` - Filter.
Returns:
  Future.

#### unlockAll

    public void unlockAll(Collection<? extends K> keys,
                 IgnitePredicate<javax.cache.Cache.Entry<K,V>>[] filter)
                   throws IgniteCheckedException

Unlocks given keys only if current thread owns the locks. Only the keys that have been locked by calling thread and pass through the filter (if any) will be unlocked. If none of the key locks is owned by current thread, then this method will do nothing.

## Transactions

Locks are not transactional and should not be used from within transactions. If you do need explicit locking within transaction, then you should use `TransactionConcurrency.PESSIMISTIC` concurrency control for transaction which will acquire explicit locks for relevant cache operations.

## Cache Flags

This method is not available if any of the following flags are set on projection: `CacheFlag.LOCAL`, `CacheFlag.READ`.

Parameters:
  `keys` - Keys to unlock.
  `filter` - Optional filter which needs to pass for individual entries to be unlocked.
Throws:
  `IgniteCheckedException` - If unlock execution resulted in error.

#### removeAll

    public void removeAll()
                   throws IgniteCheckedException

Removes mappings from cache for entries for which the optionally passed in filters do pass. If passed in filters are `null`, then all entries in cache will be enrolled into transaction.

USE WITH CARE - if your cache has many entries that pass through the filter or if filter is empty, then transaction will quickly become very heavy and slow. Also, locks are acquired in undefined order, so it may cause a deadlock when used with other concurrent transactional updates.

If write-through is enabled, the values will be removed from `CacheStore` via `CacheStore#removeAll(Transaction, Collection)` method.

## Transactions

This method is transactional and will enlist the entry into ongoing transaction if there is one.

## Cache Flags

This method is not available if any of the following flags are set on projection: `CacheFlag.LOCAL`, `CacheFlag.READ`.

Throws:
  `IgniteCheckedException` - If remove failed.

#### removeAllAsync

    public IgniteInternalFuture<?> removeAllAsync()

Returns:
  Remove future.

#### onDeferredDelete

    public void onDeferredDelete(GridCacheEntryEx<K,V> entry,
                        GridCacheVersion ver)

Specified by:
  `onDeferredDelete` in class `GridCacheAdapter<K,V>`
Parameters:
  `entry` - Entry.
  `ver` - Version.

2015 Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Fabric | : ver. 1.0.0-RC1
Release Date | : February 17 2015