Show / Hide Table of Contents

# Interface ICacheClient<TK, TV>

Client cache API. See GetCache<TK, TV>(String).

###### Namespace: Apache.Ignite.Core.Client.Cache

###### Assembly: Apache.Ignite.Core.dll

##### Syntax

    public interface ICacheClient<TK, TV>

##### Type Parameters

Name | Description
--- | ---
TK |
TV |

### Properties

#### Item[TK]

Gets or sets a cache value with the specified key. Shortcut to Get(TK) and Put(TK, TV)

##### Declaration

    TV this[TK key] { get; set; }

##### Parameters

Type | Name | Description
--- | --- | ---
TK | key | Key.

##### Property Value

Type | Description
--- | ---
TV | Cache value with the specified key.

##### Exceptions

Type | Condition
--- | ---
System.Collections.Generic.KeyNotFoundException | If the key is not present in the cache.

#### Name

Name of this cache (`null` for default cache).

##### Declaration

    string Name { get; }

##### Property Value

Type | Description
--- | ---
System.String |

### Methods

#### Clear()

Clears the contents of the cache, without notifying listeners or CacheWriters.

##### Declaration

    void Clear()

#### Clear(TK)

Clear entry from the cache, without notifying listeners or CacheWriters.

##### Declaration

    void Clear(TK key)

##### Parameters

Type | Name | Description
--- | --- | ---
TK | key | Key to clear.

#### ClearAll(IEnumerable<TK>)

Clear entries from the cache, without notifying listeners or CacheWriters.

##### Declaration

    void ClearAll(IEnumerable<TK> keys)

##### Parameters

Type | Name | Description
--- | --- | ---
System.Collections.Generic.IEnumerable<TK> | keys | Keys to clear.

#### ClearAllAsync(IEnumerable<TK>)

Clear entries from the cache, without notifying listeners or CacheWriters.

##### Declaration

    Task ClearAllAsync(IEnumerable<TK> keys)

##### Parameters

Type | Name | Description
--- | --- | ---
System.Collections.Generic.IEnumerable<TK> | keys | Keys to clear.

##### Returns

Type | Description
--- | ---
System.Threading.Tasks.Task |

#### ClearAsync()

Clears the contents of the cache, without notifying listeners or CacheWriters.

##### Declaration

    Task ClearAsync()

##### Returns

Type | Description
--- | ---
System.Threading.Tasks.Task |

#### ClearAsync(TK)

Clear entry from the cache, without notifying listeners or CacheWriters.

##### Declaration

    Task ClearAsync(TK key)

##### Parameters

Type | Name | Description
--- | --- | ---
TK | key | Key to clear.

##### Returns

Type | Description
--- | ---
System.Threading.Tasks.Task |

#### ContainsKey(TK)

Check if cache contains mapping for this key.

##### Declaration

    bool ContainsKey(TK key)

##### Parameters

Type | Name | Description
--- | --- | ---
TK | key | Key.

##### Returns

Type | Description
--- | ---
System.Boolean | True if cache contains mapping for this key.

#### ContainsKeyAsync(TK)

Check if cache contains mapping for this key.

##### Declaration

    Task<bool> ContainsKeyAsync(TK key)

##### Parameters

Type | Name | Description
--- | --- | ---
TK | key | Key.

##### Returns

Type | Description
--- | ---
System.Threading.Tasks.Task<System.Boolean> | True if cache contains mapping for this key.

#### ContainsKeys(IEnumerable<TK>)

Check if cache contains mapping for these keys.

##### Declaration

    bool ContainsKeys(IEnumerable<TK> keys)

##### Parameters

Type | Name | Description
--- | --- | ---
System.Collections.Generic.IEnumerable<TK> | keys | Keys.

##### Returns

Type | Description
--- | ---
System.Boolean | True if cache contains mapping for all these keys.

#### ContainsKeysAsync(IEnumerable<TK>)

Check if cache contains mapping for these keys.

##### Declaration

    Task<bool> ContainsKeysAsync(IEnumerable<TK> keys)

##### Parameters

Type | Name | Description
--- | --- | ---
System.Collections.Generic.IEnumerable<TK> | keys | Keys.

##### Returns

Type | Description
--- | ---
System.Threading.Tasks.Task<System.Boolean> | True if cache contains mapping for all these keys.

#### Get(TK)

Retrieves value mapped to the specified key from cache.

##### Declaration

    TV Get(TK key)

##### Parameters

Type | Name | Description
--- | --- | ---
TK | key | Key.

##### Returns

Type | Description
--- | ---
TV | Value.

##### Exceptions

Type | Condition
--- | ---
System.Collections.Generic.KeyNotFoundException | If the key is not present in the cache.

#### GetAll(IEnumerable<TK>)

Retrieves values mapped to the specified keys from cache.

##### Declaration

    ICollection<ICacheEntry<TK, TV>> GetAll(IEnumerable<TK> keys)

##### Parameters

Type | Name | Description
--- | --- | ---
System.Collections.Generic.IEnumerable<TK> | keys | Keys.

##### Returns

Type | Description
--- | ---
System.Collections.Generic.ICollection<ICacheEntry<TK, TV>> | Map of key-value pairs.

#### GetAllAsync(IEnumerable<TK>)

Retrieves values mapped to the specified keys from cache.

##### Declaration

    Task<ICollection<ICacheEntry<TK, TV>>> GetAllAsync(IEnumerable<TK> keys)

##### Parameters

Type | Name | Description
--- | --- | ---
System.Collections.Generic.IEnumerable<TK> | keys | Keys.

##### Returns

Type | Description
--- | ---
System.Threading.Tasks.Task<System.Collections.Generic.ICollection<ICacheEntry<TK, TV>>> | Map of key-value pairs.

#### GetAndPut(TK, TV)

Associates the specified value with the specified key in this cache, returning an existing value if one existed.

##### Declaration

    CacheResult<TV> GetAndPut(TK key, TV val)

##### Parameters

Type | Name | Description
--- | --- | ---
TK | key | Key with which the specified value is to be associated.
TV | val | Value to be associated with the specified key.

##### Returns

Type | Description
--- | ---
CacheResult<TV> | The value associated with the key at the start of the operation.

#### GetAndPutAsync(TK, TV)

Associates the specified value with the specified key in this cache, returning an existing value if one existed.

##### Declaration

    Task<CacheResult<TV>> GetAndPutAsync(TK key, TV val)

##### Parameters

Type | Name | Description
--- | --- | ---
TK | key | Key with which the specified value is to be associated.
TV | val | Value to be associated with the specified key.

##### Returns

Type | Description
--- | ---
System.Threading.Tasks.Task<CacheResult<TV>> | The value associated with the key at the start of the operation.

#### GetAndPutIfAbsent(TK, TV)

Stores given key-value pair in cache only if cache had no previous mapping for it.

##### Declaration

    CacheResult<TV> GetAndPutIfAbsent(TK key, TV val)

##### Parameters

Type | Name | Description
--- | --- | ---
TK | key | Key to store in cache.
TV | val | Value to be associated with the given key.

##### Returns

Type | Description
--- | ---
CacheResult<TV> | Previously contained value regardless of whether put happened or not.

#### GetAndPutIfAbsentAsync(TK, TV)

Stores given key-value pair in cache only if cache had no previous mapping for it.

##### Declaration

    Task<CacheResult<TV>> GetAndPutIfAbsentAsync(TK key, TV val)

##### Parameters

Type | Name | Description
--- | --- | ---
TK | key | Key to store in cache.
TV | val | Value to be associated with the given key.

##### Returns

Type | Description
--- | ---
System.Threading.Tasks.Task<CacheResult<TV>> | Previously contained value regardless of whether put happened or not.

#### GetAndRemove(TK)

Atomically removes the entry for a key only if currently mapped to some value.

##### Declaration

    CacheResult<TV> GetAndRemove(TK key)

##### Parameters

Type | Name | Description
--- | --- | ---
TK | key | Key with which the specified value is associated.

##### Returns

Type | Description
--- | ---
CacheResult<TV> | The value if one existed.

#### GetAndRemoveAsync(TK)

Atomically removes the entry for a key only if currently mapped to some value.

##### Declaration

    Task<CacheResult<TV>> GetAndRemoveAsync(TK key)

##### Parameters

Type | Name | Description
--- | --- | ---
TK | key | Key with which the specified value is associated.

##### Returns

Type | Description
--- | ---
System.Threading.Tasks.Task<CacheResult<TV>> | The value if one existed.

#### GetAndReplace(TK, TV)

Atomically replaces the value for a given key if and only if there is a value currently mapped by the key.

##### Declaration

    CacheResult<TV> GetAndReplace(TK key, TV val)

##### Parameters

Type | Name | Description
--- | --- | ---
TK | key | Key with which the specified value is to be associated.
TV | val | Value to be associated with the specified key.

##### Returns

Type | Description
--- | ---
CacheResult<TV> | The previous value associated with the specified key.

#### GetAndReplaceAsync(TK, TV)

Atomically replaces the value for a given key if and only if there is a value currently mapped by the key.

##### Declaration

    Task<CacheResult<TV>> GetAndReplaceAsync(TK key, TV val)

##### Parameters

Type | Name | Description
--- | --- | ---
TK | key | Key with which the specified value is to be associated.
TV | val | Value to be associated with the specified key.

##### Returns

Type | Description
--- | ---
System.Threading.Tasks.Task<CacheResult<TV>> | The previous value associated with the specified key.

#### GetAsync(TK)

Retrieves value mapped to the specified key from cache.

##### Declaration

    Task<TV> GetAsync(TK key)

##### Parameters

Type | Name | Description
--- | --- | ---
TK | key | Key.

##### Returns

Type | Description
--- | ---
System.Threading.Tasks.Task<TV> | Value.

##### Exceptions

Type | Condition
--- | ---
System.Collections.Generic.KeyNotFoundException | If the key is not present in the cache.

#### GetConfiguration()

Gets the cache configuration.

##### Declaration

    CacheClientConfiguration GetConfiguration()

##### Returns

Type | Description
--- | ---
CacheClientConfiguration |

#### GetSize(CachePeekMode[])

Gets the number of all entries cached across all nodes.

NOTE: this operation is distributed and will query all participating nodes for their cache sizes.

##### Declaration

    long GetSize(params CachePeekMode[] modes)

##### Parameters

Type | Name | Description
--- | --- | ---
CachePeekMode[] | modes | Optional peek modes. If not provided, then total cache size is returned.

##### Returns

Type | Description
--- | ---
System.Int64 | Cache size across all nodes.

#### GetSizeAsync(CachePeekMode[])

Gets the number of all entries cached across all nodes.

NOTE: this operation is distributed and will query all participating nodes for their cache sizes.

##### Declaration

    Task<long> GetSizeAsync(params CachePeekMode[] modes)

##### Parameters

Type | Name | Description
--- | --- | ---
CachePeekMode[] | modes | Optional peek modes. If not provided, then total cache size is returned.

##### Returns

Type | Description
--- | ---
System.Threading.Tasks.Task<System.Int64> | Cache size across all nodes.

#### Put(TK, TV)

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.

##### Declaration

    void Put(TK key, TV val)

##### Parameters

Type | Name | Description
--- | --- | ---
TK | key | Key with which the specified value is to be associated.
TV | val | Value to be associated with the specified key.

#### PutAll(IEnumerable<KeyValuePair<TK, TV>>)

Stores given key-value pairs in cache.

##### Declaration

    void PutAll(IEnumerable<KeyValuePair<TK, TV>> vals)

##### Parameters

Type | Name | Description
--- | --- | ---
System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<TK, TV>> | vals | Key-value pairs to store in cache.

#### PutAllAsync(IEnumerable<KeyValuePair<TK, TV>>)

Stores given key-value pairs in cache.

##### Declaration

    Task PutAllAsync(IEnumerable<KeyValuePair<TK, TV>> vals)

##### Parameters

Type | Name | Description
--- | --- | ---
System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<TK, TV>> | vals | Key-value pairs to store in cache.

##### Returns

Type | Description
--- | ---
System.Threading.Tasks.Task |

#### PutAsync(TK, TV)

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.

##### Declaration

    Task PutAsync(TK key, TV val)

##### Parameters

Type | Name | Description
--- | --- | ---
TK | key | Key with which the specified value is to be associated.
TV | val | Value to be associated with the specified key.

##### Returns

Type | Description
--- | ---
System.Threading.Tasks.Task |

#### PutIfAbsent(TK, TV)

Atomically associates the specified key with the given value if it is not already associated with a value.

##### Declaration

    bool PutIfAbsent(TK key, TV val)

##### Parameters

Type | Name | Description
--- | --- | ---
TK | key | Key with which the specified value is to be associated.
TV | val | Value to be associated with the specified key.

##### Returns

Type | Description
--- | ---
System.Boolean | True if a value was set.

#### PutIfAbsentAsync(TK, TV)

Atomically associates the specified key with the given value if it is not already associated with a value.

##### Declaration

    Task<bool> PutIfAbsentAsync(TK key, TV val)

##### Parameters

Type | Name | Description
--- | --- | ---
TK | key | Key with which the specified value is to be associated.
TV | val | Value to be associated with the specified key.

##### Returns

Type | Description
--- | ---
System.Threading.Tasks.Task<System.Boolean> | True if a value was set.

#### Query(ScanQuery<TK, TV>)

Executes a Scan query.

##### Declaration

    IQueryCursor<ICacheEntry<TK, TV>> Query(ScanQuery<TK, TV> scanQuery)

##### Parameters

Type | Name | Description
--- | --- | ---
ScanQuery<TK, TV> | scanQuery | Scan query.

##### Returns

Type | Description
--- | ---
IQueryCursor<ICacheEntry<TK, TV>> | Query cursor.

#### Query(SqlFieldsQuery)

Executes an SQL Fields query.

##### Declaration

    IFieldsQueryCursor Query(SqlFieldsQuery sqlFieldsQuery)

##### Parameters

Type | Name | Description
--- | --- | ---
SqlFieldsQuery | sqlFieldsQuery | SQL query.

##### Returns

Type | Description
--- | ---
IFieldsQueryCursor | Query cursor.

#### Query(SqlQuery)

Executes an SQL query.

##### Declaration

    [Obsolete("Use SqlFieldsQuery instead. For strongly-typed queries use Apache.Ignite.Linq. SqlQuery is a limited subset of SqlFieldsQuery.")]
    IQueryCursor<ICacheEntry<TK, TV>> Query(SqlQuery sqlQuery)

##### Parameters

Type | Name | Description
--- | --- | ---
SqlQuery | sqlQuery | SQL query.

##### Returns

Type | Description
--- | ---
IQueryCursor<ICacheEntry<TK, TV>> | Query cursor.

#### Remove(TK)

Removes given key mapping from cache, notifying listeners and cache writers.

##### Declaration

    bool Remove(TK key)

##### Parameters

Type | Name | Description
--- | --- | ---
TK | key | Key to remove.

##### Returns

Type | Description
--- | ---
System.Boolean | True if entry was removed, false otherwise.

#### Remove(TK, TV)

Removes given key mapping from cache if one exists and value is equal to the passed in value.

##### Declaration

    bool Remove(TK key, TV val)

##### Parameters

Type | Name | Description
--- | --- | ---
TK | key | Key whose mapping is to be removed from cache.
TV | val | Value to match against currently cached value.

##### Returns

Type | Description
--- | ---
System.Boolean | True if entry was removed, false otherwise.

#### RemoveAll()

Removes all mappings from cache, notifying listeners and cache writers.

##### Declaration

    void RemoveAll()

#### RemoveAll(IEnumerable<TK>)

Removes given key mappings from cache, notifying listeners and cache writers.

##### Declaration

    void RemoveAll(IEnumerable<TK> keys)

##### Parameters

Type | Name | Description
--- | --- | ---
System.Collections.Generic.IEnumerable<TK> | keys | Keys to be removed from cache.

#### RemoveAllAsync()

Removes all mappings from cache, notifying listeners and cache writers.

##### Declaration

    Task RemoveAllAsync()

##### Returns

Type | Description
--- | ---
System.Threading.Tasks.Task |

#### RemoveAllAsync(IEnumerable<TK>)

Removes given key mappings from cache, notifying listeners and cache writers.

##### Declaration

    Task RemoveAllAsync(IEnumerable<TK> keys)

##### Parameters

Type | Name | Description
--- | --- | ---
System.Collections.Generic.IEnumerable<TK> | keys | Keys to be removed from cache.

##### Returns

Type | Description
--- | ---
System.Threading.Tasks.Task |

#### RemoveAsync(TK)

Removes given key mapping from cache, notifying listeners and cache writers.

##### Declaration

    Task<bool> RemoveAsync(TK key)

##### Parameters

Type | Name | Description
--- | --- | ---
TK | key | Key to remove.

##### Returns

Type | Description
--- | ---
System.Threading.Tasks.Task<System.Boolean> | True if entry was removed, false otherwise.

#### RemoveAsync(TK, TV)

Removes given key mapping from cache if one exists and value is equal to the passed in value.

##### Declaration

    Task<bool> RemoveAsync(TK key, TV val)

##### Parameters

Type | Name | Description
--- | --- | ---
TK | key | Key whose mapping is to be removed from cache.
TV | val | Value to match against currently cached value.

##### Returns

Type | Description
--- | ---
System.Threading.Tasks.Task<System.Boolean> | True if entry was removed, false otherwise.

#### Replace(TK, TV)

Stores given key-value pair in cache only if there is a previous mapping for it.

##### Declaration

    bool Replace(TK key, TV val)

##### Parameters

Type | Name | Description
--- | --- | ---
TK | key | Key to store in cache.
TV | val | Value to be associated with the given key.

##### Returns

Type | Description
--- | ---
System.Boolean | True if the value was replaced.

#### Replace(TK, TV, TV)

Stores given key-value pair in cache only if only if the previous value is equal to the old value passed as argument.

##### Declaration

    bool Replace(TK key, TV oldVal, TV newVal)

##### Parameters

Type | Name | Description
--- | --- | ---
TK | key | Key to store in cache.
TV | oldVal | Old value to match.
TV | newVal | Value to be associated with the given key.

##### Returns

Type | Description
--- | ---
System.Boolean | True if replace happened, false otherwise.

#### ReplaceAsync(TK, TV)

Stores given key-value pair in cache only if there is a previous mapping for it.

##### Declaration

    Task<bool> ReplaceAsync(TK key, TV val)

##### Parameters

Type | Name | Description
--- | --- | ---
TK | key | Key to store in cache.
TV | val | Value to be associated with the given key.

##### Returns

Type | Description
--- | ---
System.Threading.Tasks.Task<System.Boolean> | True if the value was replaced.

#### ReplaceAsync(TK, TV, TV)

Stores given key-value pair in cache only if only if the previous value is equal to the old value passed as argument.

##### Declaration

    Task<bool> ReplaceAsync(TK key, TV oldVal, TV newVal)

##### Parameters

Type | Name | Description
--- | --- | ---
TK | key | Key to store in cache.
TV | oldVal | Old value to match.
TV | newVal | Value to be associated with the given key.

##### Returns

Type | Description
--- | ---
System.Threading.Tasks.Task<System.Boolean> | True if replace happened, false otherwise.

#### TryGet(TK, out TV)

Retrieves value mapped to the specified key from cache.

##### Declaration

    bool TryGet(TK key, out TV value)

##### Parameters

Type | Name | Description
--- | --- | ---
TK | key | Key.
TV | value | When this method returns, the value associated with the specified key, if the key is found; otherwise, the default value for the type of the value parameter. This parameter is passed uninitialized.

##### Returns

Type | Description
--- | ---
System.Boolean | true if the cache contains an element with the specified key; otherwise, false.

#### TryGetAsync(TK)

Retrieves value mapped to the specified key from cache.

##### Declaration

    Task<CacheResult<TV>> TryGetAsync(TK key)

##### Parameters

Type | Name | Description
--- | --- | ---
TK | key | Key.

##### Returns

Type | Description
--- | ---
System.Threading.Tasks.Task<CacheResult<TV>> | CacheResult<T> containing a bool success flag and a value.

#### WithExpiryPolicy(IExpiryPolicy)

Returns cache with the specified expired policy set. This policy will be used for each operation invoked on the returned cache.

Unlike the WithExpiryPolicy(IExpiryPolicy) method, expiry durations are retrieved from specified IExpiryPolicy on every key-value API operation.

##### Declaration

    ICacheClient<TK, TV> WithExpiryPolicy(IExpiryPolicy plc)

##### Parameters

Type | Name | Description
--- | --- | ---
IExpiryPolicy | plc | Expiry policy to use.

##### Returns

Type | Description
--- | ---
ICacheClient<TK, TV> | Cache instance with the specified expiry policy set.

#### WithKeepBinary<TK1, TV1>()

Gets cache with KeepBinary mode enabled, changing key and/or value types if necessary. You can only change key/value types when transitioning from non-binary to binary cache; Changing type of binary cache is not allowed and will throw an System.InvalidOperationException.

##### Declaration

    ICacheClient<TK1, TV1> WithKeepBinary<TK1, TV1>()

##### Returns

Type | Description
--- | ---
ICacheClient<TK1, TV1> | Cache instance with binary mode enabled.

##### Type Parameters

Name | Description
--- | ---
TK1 | Key type in binary mode.
TV1 | Value type in binary mode.

### Extension Methods

CacheClientLinqExtensions.AsCacheQueryable<TKey, TValue>(ICacheClient<TKey, TValue>)
CacheClientLinqExtensions.AsCacheQueryable<TKey, TValue>(ICacheClient<TKey, TValue>, Boolean)
CacheClientLinqExtensions.AsCacheQueryable<TKey, TValue>(ICacheClient<TKey, TValue>, Boolean, String)
CacheClientLinqExtensions.AsCacheQueryable<TKey, TValue>(ICacheClient<TKey, TValue>, QueryOptions)