| Apache Ignite C++

Public Types | Public Member Functions | Friends | List of all members
ignite::thin::cache::CacheClient< K, V > Class Template Reference

Cache client class template. More...

`#include <cache_client.h>`

## Public Types
typedef K | KeyType
| Key type.
typedef V | ValueType
| Value type.

## Public Member Functions
| CacheClient (common::concurrent::SharedPointer< void > impl)
| Constructor. More...
| CacheClient ()
| Default constructor.
| ~CacheClient ()
| Destructor.
void | Put (const KeyType &key, const ValueType &value)
| Associate the specified value with the specified key in the cache. More...
template<typename InIter >
void | PutAll (InIter begin, InIter end)
| Stores given key-value pairs in cache. More...
template<typename Map >
void | PutAll (const Map &vals)
| Stores given key-value pairs in cache. More...
void | Get (const KeyType &key, ValueType &value)
| Get value from the cache. More...
ValueType | Get (const KeyType &key)
| Get value from cache. More...
template<typename InIter , typename OutIter >
void | GetAll (InIter begin, InIter end, OutIter dst)
| Retrieves values mapped to the specified keys from cache. More...
template<typename Set , typename Map >
void | GetAll (const Set &keys, Map &res)
| Retrieves values mapped to the specified keys from cache. More...
bool | Replace (const K &key, const V &value)
| Stores given key-value pair in cache only if there is a previous mapping for it. More...
bool | Replace (const KeyType &key, const ValueType &oldVal, const ValueType &newVal)
| Stores given key-value pair in cache only if the previous value is equal to the old value passed as argument. More...
bool | ContainsKey (const KeyType &key)
| Check if the cache contains a value for the specified key. More...
template<typename Set >
bool | ContainsKeys (const Set &keys)
| Check if cache contains mapping for these keys. More...
template<typename InIter >
bool | ContainsKeys (InIter begin, InIter end)
| Check if cache contains mapping for these keys. More...
int64_t | GetSize (int32_t peekModes)
| Gets the number of all entries cached across all nodes. More...
bool | Remove (const KeyType &key)
| Removes given key mapping from cache. More...
bool | Remove (const KeyType &key, const ValueType &val)
| Removes given key mapping from cache if one exists and value is equal to the passed in value. More...
template<typename Set >
void | RemoveAll (const Set &keys)
| Removes given key mappings from cache. More...
template<typename InIter >
void | RemoveAll (InIter begin, InIter end)
| Removes given key mappings from cache. More...
void | RemoveAll ()
| Removes all mappings from cache. More...
void | Clear (const KeyType &key)
| Clear entry from the cache and swap storage, without notifying listeners or CacheWriters. More...
void | Clear ()
| Clear cache.
template<typename Set >
void | ClearAll (const Set &keys)
| Clear entries from the cache and swap storage, without notifying listeners or CacheWriters. More...
template<typename InIter >
void | ClearAll (InIter begin, InIter end)
| Clear entries from the cache and swap storage, without notifying listeners or CacheWriters. More...
void | GetAndPut (const KeyType &key, const ValueType &valIn, ValueType &valOut)
| Associates the specified value with the specified key in this cache, returning an existing value if one existed. More...
ValueType | GetAndPut (const KeyType &key, const ValueType &valIn)
| Associates the specified value with the specified key in this cache, returning an existing value if one existed. More...
void | GetAndRemove (const KeyType &key, ValueType &valOut)
| Atomically removes the entry for a key only if currently mapped to some value. More...
ValueType | GetAndRemove (const KeyType &key)
| Atomically removes the entry for a key only if currently mapped to some value. More...
void | GetAndReplace (const KeyType &key, const ValueType &valIn, ValueType &valOut)
| Atomically replaces the value for a given key if and only if there is a value currently mapped by the key. More...
ValueType | GetAndReplace (const KeyType &key, const ValueType &valIn)
| Atomically replaces the value for a given key if and only if there is a value currently mapped by the key. More...
bool | PutIfAbsent (const KeyType &key, const ValueType &val)
| Atomically associates the specified key with the given value if it is not already associated with a value. More...
void | GetAndPutIfAbsent (const KeyType &key, const ValueType &valIn, ValueType &valOut)
| Stores given key-value pair in cache only if cache had no previous mapping for it. More...
ValueType | GetAndPutIfAbsent (const KeyType &key, const ValueType &valIn)
| Stores given key-value pair in cache only if cache had no previous mapping for it. More...
query::QueryFieldsCursor | Query (const query::SqlFieldsQuery &qry)
| Perform SQL fields query. More...
void | RefreshAffinityMapping ()
| Refresh affinity mapping. More...

## Friends
class | impl::thin::cache::CacheClientProxy

## Detailed Description

### template<typename K, typename V>
class ignite::thin::cache::CacheClient< K, V >

Cache client class template.

Main entry point for all Data Grid APIs.

Both key and value types should be default-constructable, copy-constructable and assignable. Also BinaryType class template should be specialized for both types, if they are not one of the basic types.

This class is implemented as a reference to an implementation so copying of this class instance will only create another reference to the same underlying object. Underlying object will be released automatically once all the instances are destructed.

Template Parameters

  K | Cache key type.
  V | Cache value type.

## Constructor & Destructor Documentation

## ◆ CacheClient()

template<typename K , typename V >

ignite::thin::cache::CacheClient< K, V >::CacheClient | ( | common::concurrent::SharedPointer< void > | impl | ) |
| inline

Constructor.

Parameters

  impl | Implementation.

## Member Function Documentation

## ◆ Clear()

template<typename K , typename V >

void ignite::thin::cache::CacheClient< K, V >::Clear | ( | const KeyType & | key | ) |
| inline

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

Entry is cleared only if it is not currently locked, and is not participating in a transaction.

Parameters

  key | Key to clear.

## ◆ ClearAll() [1/2]

template<typename K , typename V >
template<typename Set >

void ignite::thin::cache::CacheClient< K, V >::ClearAll | ( | const Set & | keys | ) |
| inline

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

Entry is cleared only if it is not currently locked, and is not participating in a transaction.

Parameters

  keys | Keys to clear.

## ◆ ClearAll() [2/2]

template<typename K , typename V >
template<typename InIter >

void ignite::thin::cache::CacheClient< K, V >::ClearAll | ( | InIter | begin,
|  | InIter | end
| ) |  |
| inline

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

Entry is cleared only if it is not currently locked, and is not participating in a transaction.

Parameters

  begin | Iterator pointing to the beginning of the key sequence.
  end | Iterator pointing to the end of the key sequence.

## ◆ ContainsKey()

template<typename K , typename V >

bool ignite::thin::cache::CacheClient< K, V >::ContainsKey | ( | const KeyType & | key | ) |
| inline

Check if the cache contains a value for the specified key.

Parameters

  key | Key whose presence in this cache is to be tested.

Returns
  `true` if the cache contains specified key.

## ◆ ContainsKeys() [1/2]

template<typename K , typename V >
template<typename Set >

bool ignite::thin::cache::CacheClient< K, V >::ContainsKeys | ( | const Set & | keys | ) |
| inline

Check if cache contains mapping for these keys.

Parameters

  keys | Keys.

Returns
  True if cache contains mapping for all these keys.

## ◆ ContainsKeys() [2/2]

template<typename K , typename V >
template<typename InIter >

bool ignite::thin::cache::CacheClient< K, V >::ContainsKeys | ( | InIter | begin,
|  | InIter | end
| ) |  |
| inline

Check if cache contains mapping for these keys.

Parameters

  begin | Iterator pointing to the beginning of the key sequence.
  end | Iterator pointing to the end of the key sequence.

Returns
  True if cache contains mapping for all these keys.

## ◆ Get() [1/2]

template<typename K , typename V >

ValueType ignite::thin::cache::CacheClient< K, V >::Get | ( | const KeyType & | key | ) |
| inline

Get value from cache.

Parameters

  key | Key.

Returns
  Value.

## ◆ Get() [2/2]

template<typename K , typename V >

void ignite::thin::cache::CacheClient< K, V >::Get | ( | const KeyType & | key,
|  | ValueType & | value
| ) |  |
| inline

Get value from the cache.

Parameters

  key | Key.
  value | Value.

## ◆ GetAll() [1/2]

template<typename K , typename V >
template<typename Set , typename Map >

void ignite::thin::cache::CacheClient< K, V >::GetAll | ( | const Set & | keys,
|  | Map & | res
| ) |  |
| inline

Retrieves values mapped to the specified keys from cache.

If some value is not present in cache, then it will be looked up from swap storage. If it's not present in swap, or if swap is disabled, and if read-through is allowed, value will be loaded from persistent store.

Parameters

  keys | Keys.
  res | Map of key-value pairs.

## ◆ GetAll() [2/2]

template<typename K , typename V >
template<typename InIter , typename OutIter >

void ignite::thin::cache::CacheClient< K, V >::GetAll | ( | InIter | begin,
|  | InIter | end,
|  | OutIter | dst
| ) |  |
| inline

Retrieves values mapped to the specified keys from cache.

If some value is not present in cache, then it will be looked up from swap storage. If it's not present in swap, or if swap is disabled, and if read-through is allowed, value will be loaded from persistent store.

Parameters

  begin | Iterator pointing to the beginning of the key sequence.
  end | Iterator pointing to the end of the key sequence.
  dst | Output iterator. Should dereference to std::pair or CacheEntry.

## ◆ GetAndPut() [1/2]

template<typename K , typename V >

ValueType ignite::thin::cache::CacheClient< K, V >::GetAndPut | ( | const KeyType & | key,
|  | const ValueType & | valIn
| ) |  |
| inline

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

Parameters

  key | Key with which the specified value is to be associated.
  valIn | Value to be associated with the specified key.

Returns
  The value associated with the key at the start of the operation or null if none was associated.

## ◆ GetAndPut() [2/2]

template<typename K , typename V >

void ignite::thin::cache::CacheClient< K, V >::GetAndPut | ( | const KeyType & | key,
|  | const ValueType & | valIn,
|  | ValueType & | valOut
| ) |  |
| inline

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

Parameters

  key | Key with which the specified value is to be associated.
  valIn | Value to be associated with the specified key.
  valOut | The value associated with the key at the start of the operation or null if none was associated.

## ◆ GetAndPutIfAbsent() [1/2]

template<typename K , typename V >

ValueType ignite::thin::cache::CacheClient< K, V >::GetAndPutIfAbsent | ( | const KeyType & | key,
|  | const ValueType & | valIn
| ) |  |
| inline

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 of PARTITIONED or 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 the returned value is not needed, method putxIfAbsent() should 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 store.

Parameters

  key | Key to store in cache.
  valIn | 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).

## ◆ GetAndPutIfAbsent() [2/2]

template<typename K , typename V >

void ignite::thin::cache::CacheClient< K, V >::GetAndPutIfAbsent | ( | const KeyType & | key,
|  | const ValueType & | valIn,
|  | ValueType & | valOut
| ) |  |
| inline

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 of PARTITIONED or 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 the returned value is not needed, method putxIfAbsent() should 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 store.

Parameters

  key | Key to store in cache.
  valIn | Value to be associated with the given key.
  valOut | Previously contained value regardless of whether put happened or not (null if there was no previous value).

## ◆ GetAndRemove() [1/2]

template<typename K , typename V >

ValueType ignite::thin::cache::CacheClient< K, V >::GetAndRemove | ( | const KeyType & | key | ) |
| inline

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

Parameters

  key | Key with which the specified value is to be associated.

Returns
  The value associated with the key at the start of the operation or null if none was associated.

## ◆ GetAndRemove() [2/2]

template<typename K , typename V >

void ignite::thin::cache::CacheClient< K, V >::GetAndRemove | ( | const KeyType & | key,
|  | ValueType & | valOut
| ) |  |
| inline

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

Parameters

  key | Key with which the specified value is to be associated.
  valOut | The value associated with the key at the start of the operation or null if none was associated.

## ◆ GetAndReplace() [1/2]

template<typename K , typename V >

ValueType ignite::thin::cache::CacheClient< K, V >::GetAndReplace | ( | const KeyType & | key,
|  | const ValueType & | valIn
| ) |  |
| inline

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

Parameters

  key | Key with which the specified value is to be associated.
  valIn | Value to be associated with the specified key.

Returns
  The value associated with the key at the start of the operation or null if none was associated.

## ◆ GetAndReplace() [2/2]

template<typename K , typename V >

void ignite::thin::cache::CacheClient< K, V >::GetAndReplace | ( | const KeyType & | key,
|  | const ValueType & | valIn,
|  | ValueType & | valOut
| ) |  |
| inline

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

Parameters

  key | Key with which the specified value is to be associated.
  valIn | Value to be associated with the specified key.
  valOut | The value associated with the key at the start of the operation or null if none was associated.

## ◆ GetSize()

template<typename K , typename V >

int64_t ignite::thin::cache::CacheClient< K, V >::GetSize | ( | int32_t | peekModes | ) |
| inline

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.

See also
  CachePeekMode for details.

Parameters

  peekModes | Peek modes mask.

Returns
  Cache size across all nodes.

## ◆ Put()

template<typename K , typename V >

void ignite::thin::cache::CacheClient< K, V >::Put | ( | const KeyType & | key,
|  | const ValueType & | value
| ) |  |
| inline

Associate the specified value with the specified key in the cache.

Parameters

  key | Key.
  value | Value.

## ◆ PutAll() [1/2]

template<typename K , typename V >
template<typename Map >

void ignite::thin::cache::CacheClient< K, V >::PutAll | ( | const Map & | vals | ) |
| inline

Stores given key-value pairs in cache.

If write-through is enabled, the stored values will be persisted to store.

Parameters

  vals | Key-value pairs to store in cache.

## ◆ PutAll() [2/2]

template<typename K , typename V >
template<typename InIter >

void ignite::thin::cache::CacheClient< K, V >::PutAll | ( | InIter | begin,
|  | InIter | end
| ) |  |
| inline

Stores given key-value pairs in cache.

If write-through is enabled, the stored values will be persisted to store.

Parameters

  begin | Iterator pointing to the beginning of the key-value pair sequence.
  end | Iterator pointing to the end of the key-value pair sequence.

## ◆ PutIfAbsent()

template<typename K , typename V >

bool ignite::thin::cache::CacheClient< K, V >::PutIfAbsent | ( | const KeyType & | key,
|  | const ValueType & | val
| ) |  |
| inline

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

Parameters

  key | Key with which the specified value is to be associated.
  val | Value to be associated with the specified key.

Returns
  True if a value was set.

## ◆ Query()

template<typename K , typename V >

query::QueryFieldsCursor ignite::thin::cache::CacheClient< K, V >::Query | ( | const query::SqlFieldsQuery & | qry | ) |
| inline

Perform SQL fields query.

Parameters

  qry | Query.

Returns
  Query fields cursor.

## ◆ RefreshAffinityMapping()

template<typename K , typename V >

void ignite::thin::cache::CacheClient< K, V >::RefreshAffinityMapping | ( |  | ) |
| inline

Refresh affinity mapping.

Deprecated:
  Does nothing since Apache Ignite 2.8. Affinity mapping is refreshed automatically now.

Retrieves affinity mapping information from remote server. This information uses to send data requests to the most appropriate nodes. This can lessen latency and improve overall performance.

It is recommended to refresh affinity mapping after every topology change, i.e. when a node enters or leaves cluster.

## ◆ Remove() [1/2]

template<typename K , typename V >

bool ignite::thin::cache::CacheClient< K, V >::Remove | ( | const KeyType & | key | ) |
| inline

Removes given key mapping from cache.

If cache previously contained value for the given key, then this value is returned. In case of PARTITIONED or REPLICATED caches, the value will be loaded from the primary node, which in its turn may load the value from the disk-based swap storage, and consecutively, if it's not in swap, from the underlying persistent storage. If the returned value is not needed, method removex() 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 value will be removed from store.

Parameters

  key | Key whose mapping is to be removed from cache.

Returns
  False if there was no matching key.

## ◆ Remove() [2/2]

template<typename K , typename V >

bool ignite::thin::cache::CacheClient< K, V >::Remove | ( | const KeyType & | key,
|  | const ValueType & | val
| ) |  |
| inline

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

If write-through is enabled, the value will be removed from store.

Parameters

  key | Key whose mapping is to be removed from cache.
  val | Value to match against currently cached value.

Returns
  True if entry was removed, false otherwise.

## ◆ RemoveAll() [1/3]

template<typename K , typename V >

void ignite::thin::cache::CacheClient< K, V >::RemoveAll | ( |  | ) |
| inline

Removes all mappings from cache.

If write-through is enabled, the value will be removed from store. This method is transactional and will enlist the entry into ongoing transaction if there is one.

## ◆ RemoveAll() [2/3]

template<typename K , typename V >
template<typename Set >

void ignite::thin::cache::CacheClient< K, V >::RemoveAll | ( | const Set & | keys | ) |
| inline

Removes given key mappings from cache.

If write-through is enabled, the value will be removed from store.

Parameters

  keys | Keys whose mappings are to be removed from cache.

## ◆ RemoveAll() [3/3]

template<typename K , typename V >
template<typename InIter >

void ignite::thin::cache::CacheClient< K, V >::RemoveAll | ( | InIter | begin,
|  | InIter | end
| ) |  |
| inline

Removes given key mappings from cache.

If write-through is enabled, the value will be removed from store.

Parameters

  begin | Iterator pointing to the beginning of the key sequence.
  end | Iterator pointing to the end of the key sequence.

## ◆ Replace() [1/2]

template<typename K , typename V >

bool ignite::thin::cache::CacheClient< K, V >::Replace | ( | const K & | key,
|  | const V & | value
| ) |  |
| inline

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

If cache previously contained value for the given key, then this value is returned. In case of PARTITIONED or 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, rom the underlying persistent storage. If write-through is enabled, the stored value will be persisted to store.

Parameters

  key | Key to store in cache.
  value | Value to be associated with the given key.

Returns
  True if the value was replaced.

## ◆ Replace() [2/2]

template<typename K , typename V >

bool ignite::thin::cache::CacheClient< K, V >::Replace | ( | const KeyType & | key,
|  | const ValueType & | oldVal,
|  | const ValueType & | newVal
| ) |  |
| inline

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

Parameters

  key | Key to store in cache.
  oldVal | Old value to match.
  newVal | Value to be associated with the given key.

Returns
  True if replace happened, false otherwise.

The documentation for this class was generated from the following file:

- cache_client.h