15 #ifndef _GRIDGAIN_CACHE 16 #define _GRIDGAIN_CACHE 21 #include <ignite/common/common.h> 22 #include <ignite/common/concurrent.h> 31 #include "gridgain/impl/cache/cache_impl.h" 32 #include "gridgain/impl/operations.h" 42 template<
typename K,
typename V>
43 class IGNITE_IMPORT_EXPORT
Cache 49 Cache(impl::cache::CacheImpl* impl) : impl(ignite::common::concurrent::SharedPointer<impl::cache::CacheImpl>(impl))
59 return impl.Get()->GetName();
72 bool res = IsEmpty(err);
88 return Size(err) == 0;
101 bool res = ContainsKey(key, err);
117 impl::In1Operation<K> op(&key);
119 return impl.Get()->ContainsKey(op, &err);
132 bool res = ContainsKeys(keys, err);
148 impl::InSetOperation<K> op(&keys);
150 return impl.Get()->ContainsKeys(op, &err);
168 V res = LocalPeek(key, peekModes, err);
189 impl::InCacheLocalPeekOperation<K> inOp(&key, peekModes);
190 impl::Out1Operation<V> outOp;
192 impl.Get()->LocalPeek(inOp, outOp, peekModes, &err);
194 return outOp.GetResult();
211 V res = Get(key, err);
231 impl::In1Operation<K> inOp(&key);
232 impl::Out1Operation<V> outOp;
234 impl.Get()->Get(inOp, outOp, &err);
236 return outOp.GetResult();
249 std::map<K, V>
GetAll(
const std::set<K>& keys)
253 std::map<K, V> res = GetAll(keys, err);
273 impl::InSetOperation<K> inOp(&keys);
274 impl::OutMapOperation<K, V> outOp;
276 impl.Get()->GetAll(inOp, outOp, &err);
278 return outOp.GetResult();
289 void Put(
const K& key,
const V& val)
309 impl::In2Operation<K, V> op(&key, &val);
311 impl.Get()->Put(op, &err);
340 impl::InMapOperation<K, V> op(&vals);
342 impl.Get()->PutAll(op, &err);
358 V res = GetAndPut(key, val, err);
377 impl::In2Operation<K, V> inOp(&key, &val);
378 impl::Out1Operation<V> outOp;
380 impl.Get()->GetAndPut(inOp, outOp, &err);
382 return outOp.GetResult();
398 V res = GetAndReplace(key, val, err);
417 impl::In2Operation<K, V> inOp(&key, &val);
418 impl::Out1Operation<V> outOp;
420 impl.Get()->GetAndReplace(inOp, outOp, &err);
422 return outOp.GetResult();
435 V res = GetAndRemove(key, err);
451 impl::In1Operation<K> inOp(&key);
452 impl::Out1Operation<V> outOp;
454 impl.Get()->GetAndRemove(inOp, outOp, &err);
456 return outOp.GetResult();
471 bool res = PutIfAbsent(key, val, err);
489 impl::In2Operation<K, V> op(&key, &val);
491 return impl.Get()->PutIfAbsent(op, &err);
514 V res = GetAndPutIfAbsent(key, val, err);
540 impl::In2Operation<K, V> inOp(&key, &val);
541 impl::Out1Operation<V> outOp;
543 impl.Get()->GetAndPutIfAbsent(inOp, outOp, &err);
545 return outOp.GetResult();
565 bool res = Replace(key, val, err);
588 impl::In2Operation<K, V> op(&key, &val);
590 return impl.Get()->Replace(op, &err);
603 bool Replace(
const K& key,
const V& oldVal,
const V& newVal)
607 bool res = Replace(key, oldVal, newVal, err);
627 impl::In3Operation<K, V, V> op(&key, &oldVal, &newVal);
629 return impl.Get()->ReplaceIfEqual(op, &err);
642 LocalEvict(keys, err);
656 impl::InSetOperation<K> op(&keys);
658 impl.Get()->LocalEvict(op, &err);
680 impl.Get()->Clear(&err);
707 impl::In1Operation<K> op(&key);
709 impl.Get()->Clear(op, &err);
736 impl::InSetOperation<K> op(&keys);
738 impl.Get()->ClearAll(op, &err);
753 LocalClear(key, err);
769 impl::In1Operation<K> op(&key);
771 impl.Get()->LocalClear(op, &err);
786 LocalClearAll(keys, err);
802 impl::InSetOperation<K> op(&keys);
804 impl.Get()->LocalClearAll(op, &err);
824 bool res = Remove(key, err);
847 impl::In1Operation<K> op(&key);
849 return impl.Get()->Remove(op, &err);
865 bool res = Remove(key, val, err);
884 impl::In2Operation<K, V> op(&key, &val);
886 return impl.Get()->RemoveIfEqual(op, &err);
900 RemoveAll(keys, err);
915 impl::InSetOperation<K> op(&keys);
917 impl.Get()->RemoveAll(op, &err);
945 return impl.Get()->RemoveAll(&err);
979 int32_t res = LocalSize(peekModes, err);
995 return impl.Get()->Size(peekModes,
true, &err);
1032 int32_t res = Size(peekModes, err);
1049 return impl.Get()->Size(peekModes,
false, &err);
1078 impl::cache::query::QueryCursorImpl* cursorImpl = impl.Get()->QuerySql(qry, &err);
1109 impl::cache::query::QueryCursorImpl* cursorImpl = impl.Get()->QueryText(qry, &err);
1140 impl::cache::query::QueryCursorImpl* cursorImpl = impl.Get()->QueryScan(qry, &err);
1171 impl::cache::query::QueryCursorImpl* cursorImpl = impl.Get()->QuerySqlFields(qry, &err);
1183 return impl.IsValid();
1188 ignite::common::concurrent::SharedPointer<impl::cache::CacheImpl> impl;
Main entry point for all Data Grid APIs.
Definition: cache.h:43
void ClearAll(const std::set< K > &keys)
Clear entries from the cache and swap storage, without notifying listeners or CacheWriters.
Definition: cache.h:718
void LocalEvict(const std::set< K > &keys)
Attempts to evict all entries associated with keys.
Definition: cache.h:638
void Put(const K &key, const V &val)
Associates the specified value with the specified key in the cache.
Definition: cache.h:289
bool Replace(const K &key, const V &oldVal, const V &newVal, GridError &err)
Stores given key-value pair in cache only if only if the previous value is equal to the old value pas...
Definition: cache.h:625
query::QueryCursor< K, V > Query(const query::ScanQuery &qry)
Perform scan query.
Definition: cache.h:1120
int32_t LocalSize(int32_t peekModes, GridError &err)
Gets the number of all entries cached on this node.
Definition: cache.h:993
query::QueryFieldsCursor Query(const query::SqlFieldsQuery &qry)
Perform sql fields query.
Definition: cache.h:1151
Cache(impl::cache::CacheImpl *impl)
Constructor.
Definition: cache.h:49
Declares gridgain::cache::query::QueryCursor class template.
void PutAll(const std::map< K, V > &vals)
Stores given key-value pairs in cache.
Definition: cache.h:321
bool ContainsKeys(const std::set< K > &keys, GridError &err)
Check if cache contains mapping for these keys.
Definition: cache.h:146
void RemoveAll(GridError &err)
Removes all mappings from cache.
Definition: cache.h:943
Peeks into all available cache storages.
Definition: cache_peek_mode.h:30
bool IsValid()
Check if the instance is valid.
Definition: cache.h:1181
const char * GetName() const
Name of this cache (null for default cache).
Definition: cache.h:57
Query fields cursor.
Definition: query_fields_cursor.h:37
Declares gridgain::cache::query::QueryFieldsCursor class.
Sql query.
Definition: query_sql.h:34
int32_t Size()
Gets the number of all entries cached across all nodes.
Definition: cache.h:1004
Declares gridgain::cache::query::SqlQuery class.
int32_t LocalSize()
Gets the number of all entries cached on this node.
Definition: cache.h:953
void Clear(const K &key, GridError &err)
Clear entry from the cache and swap storage, without notifying listeners or CacheWriters.
Definition: cache.h:705
Text query.
Definition: query_text.h:32
Declares gridgain::cache::CachePeekMode enum.
int32_t Size(int32_t peekModes)
Gets the number of all entries cached across all nodes.
Definition: cache.h:1028
bool PutIfAbsent(const K &key, const V &val)
Atomically associates the specified key with the given value if it is not already associated with a v...
Definition: cache.h:467
V GetAndRemove(const K &key)
Atomically removes the entry for a key only if currently mapped to some value.
Definition: cache.h:431
void PutAll(const std::map< K, V > &vals, GridError &err)
Stores given key-value pairs in cache.
Definition: cache.h:338
V GetAndPut(const K &key, const V &val, GridError &err)
Associates the specified value with the specified key in this cache, returning an existing value if o...
Definition: cache.h:375
void Clear()
Clear cache.
Definition: cache.h:664
bool ContainsKeys(const std::set< K > &keys)
Check if cache contains mapping for these keys.
Definition: cache.h:128
void RemoveAll(const std::set< K > &keys, GridError &err)
Removes given key mappings from cache.
Definition: cache.h:913
V GetAndRemove(const K &key, GridError &err)
Atomically removes the entry for a key only if currently mapped to some value.
Definition: cache.h:449
Scab query.
Definition: query_scan.h:32
V GetAndPut(const K &key, const V &val)
Associates the specified value with the specified key in this cache, returning an existing value if o...
Definition: cache.h:354
void RemoveAll()
Removes all mappings from cache.
Definition: cache.h:927
void ClearAll(const std::set< K > &keys, GridError &err)
Clear entries from the cache and swap storage, without notifying listeners or CacheWriters.
Definition: cache.h:734
bool ContainsKey(const K &key, GridError &err)
Check if cache contains mapping for this key.
Definition: cache.h:115
bool Replace(const K &key, const V &oldVal, const V &newVal)
Stores given key-value pair in cache only if only if the previous value is equal to the old value pas...
Definition: cache.h:603
Declares gridgain::GridError class.
V LocalPeek(const K &key, int32_t peekModes, GridError &err)
Peeks at cached value using optional set of peek modes.
Definition: cache.h:187
void Clear(GridError &err)
Clear cache.
Definition: cache.h:678
std::map< K, V > GetAll(const std::set< K > &keys)
Retrieves values mapped to the specified keys from cache.
Definition: cache.h:249
bool ContainsKey(const K &key)
Check if cache contains mapping for this key.
Definition: cache.h:97
Sql fields query.
Definition: query_sql_fields.h:34
V GetAndPutIfAbsent(const K &key, const V &val, GridError &err)
Stores given key-value pair in cache only if cache had no previous mapping for it.
Definition: cache.h:538
bool Replace(const K &key, const V &val)
Stores given key-value pair in cache only if there is a previous mapping for it.
Definition: cache.h:561
query::QueryCursor< K, V > Query(const query::SqlQuery &qry, GridError &err)
Perform SQL query.
Definition: cache.h:1076
void LocalClear(const K &key)
Clear entry from the cache and swap storage, without notifying listeners or CacheWriters.
Definition: cache.h:749
void LocalEvict(const std::set< K > &keys, GridError &err)
Attempts to evict all entries associated with keys.
Definition: cache.h:654
std::map< K, V > GetAll(const std::set< K > &keys, GridError &err)
Retrieves values mapped to the specified keys from cache.
Definition: cache.h:271
Query cursor.
Definition: query_cursor.h:37
bool Replace(const K &key, const V &val, GridError &err)
Stores given key-value pair in cache only if there is a previous mapping for it.
Definition: cache.h:586
query::QueryCursor< K, V > Query(const query::ScanQuery &qry, GridError &err)
Perform scan query.
Definition: cache.h:1138
void LocalClear(const K &key, GridError &err)
Clear entry from the cache and swap storage, without notifying listeners or CacheWriters.
Definition: cache.h:767
bool IsEmpty(GridError &err)
Checks whether this cache contains no key-value mappings.
Definition: cache.h:86
int32_t LocalSize(int32_t peekModes)
Gets the number of all entries cached on this node.
Definition: cache.h:975
V LocalPeek(const K &key, int32_t peekModes)
Peeks at cached value using optional set of peek modes.
Definition: cache.h:164
V Get(const K &key, GridError &err)
Retrieves value mapped to the specified key from cache.
Definition: cache.h:229
void RemoveAll(const std::set< K > &keys)
Removes given key mappings from cache.
Definition: cache.h:896
void LocalClearAll(const std::set< K > &keys)
Clear entries from the cache and swap storage, without notifying listeners or CacheWriters.
Definition: cache.h:782
Declares gridgain::cache::query::SqlFieldsQuery class.
int32_t LocalSize(GridError &err)
Gets the number of all entries cached on this node.
Definition: cache.h:964
query::QueryCursor< K, V > Query(const query::SqlQuery &qry)
Perform SQL query.
Definition: cache.h:1058
bool Remove(const K &key, GridError &err)
Removes given key mapping from cache.
Definition: cache.h:845
query::QueryCursor< K, V > Query(const query::TextQuery &qry)
Perform text query.
Definition: cache.h:1089
V GetAndPutIfAbsent(const K &key, const V &val)
Stores given key-value pair in cache only if cache had no previous mapping for it.
Definition: cache.h:510
Declares gridgain::cache::query::ScanQuery class.
query::QueryFieldsCursor Query(const query::SqlFieldsQuery &qry, GridError &err)
Perform sql fields query.
Definition: cache.h:1169
bool Remove(const K &key)
Removes given key mapping from cache.
Definition: cache.h:820
static void ThrowIfNeeded(GridError &err)
Throw an error if code is not GG_SUCCESS.
Definition: grid_error.cpp:22
void Clear(const K &key)
Clear entry from the cache and swap storage, without notifying listeners or CacheWriters.
Definition: cache.h:689
bool PutIfAbsent(const K &key, const V &val, GridError &err)
Atomically associates the specified key with the given value if it is not already associated with a v...
Definition: cache.h:487
bool Remove(const K &key, const V &val)
Removes given key mapping from cache if one exists and value is equal to the passed in value...
Definition: cache.h:861
int32_t Size(int32_t peekModes, GridError &err)
Gets the number of all entries cached across all nodes.
Definition: cache.h:1047
V GetAndReplace(const K &key, const V &val)
Atomically replaces the value for a given key if and only if there is a value currently mapped by the...
Definition: cache.h:394
GridGain API.
Definition: cache.h:35
Grid error information.
Definition: grid_error.h:70
void LocalClearAll(const std::set< K > &keys, GridError &err)
Clear entries from the cache and swap storage, without notifying listeners or CacheWriters.
Definition: cache.h:800
bool Remove(const K &key, const V &val, GridError &err)
Removes given key mapping from cache if one exists and value is equal to the passed in value...
Definition: cache.h:882
int32_t Size(GridError &err)
Gets the number of all entries cached across all nodes.
Definition: cache.h:1016
V Get(const K &key)
Retrieves value mapped to the specified key from cache.
Definition: cache.h:207
V GetAndReplace(const K &key, const V &val, GridError &err)
Atomically replaces the value for a given key if and only if there is a value currently mapped by the...
Definition: cache.h:415
query::QueryCursor< K, V > Query(const query::TextQuery &qry, GridError &err)
Perform text query.
Definition: cache.h:1107
void Put(const K &key, const V &val, GridError &err)
Associates the specified value with the specified key in the cache.
Definition: cache.h:307
Declares gridgain::cache::query::TextQuery class.
bool IsEmpty()
Checks whether this cache contains no key-value mappings.
Definition: cache.h:68