 |
GridGain C++
|
Go to the documentation of this file.
22 #ifndef _IGNITE_CACHE_CACHE
23 #define _IGNITE_CACHE_CACHE
28 #include <ignite/common/common.h>
29 #include <ignite/common/concurrent.h>
41 #include <ignite/impl/cache/cache_impl.h>
42 #include <ignite/impl/cache/cache_entry_processor_holder.h>
43 #include <ignite/impl/operations.h>
44 #include <ignite/impl/module_manager.h>
66 template<
typename K,
typename V>
67 class IGNITE_IMPORT_EXPORT
Cache
77 Cache(impl::cache::CacheImpl* impl) :
92 return impl.Get()->GetName();
107 bool res = IsEmpty(err);
125 return Size(err) == 0;
140 bool res = ContainsKey(key, err);
158 impl::In1Operation<K> op(key);
160 return impl.Get()->ContainsKey(op, err);
175 bool res = ContainsKeys(keys, err);
191 template<
typename InputIter>
196 impl::InIterOperation<K, V, InputIter> op(begin, end);
198 bool res = impl.Get()->ContainsKeys(op, err);
216 impl::InSetOperation<K> op(keys);
218 return impl.Get()->ContainsKeys(op, err);
238 V res = LocalPeek(key, peekModes, err);
263 impl::InCacheLocalPeekOperation<K> inOp(key, peekModes);
264 impl::Out1Operation<V> outOp(val);
266 impl.Get()->LocalPeek(inOp, outOp, err);
287 V res = Get(key, err);
310 impl::In1Operation<K> inOp(key);
311 impl::Out1Operation<V> outOp(val);
313 impl.Get()->Get(inOp, outOp, err);
330 std::map<K, V>
GetAll(
const std::set<K>& keys)
334 std::map<K, V> res = GetAll(keys, err);
358 impl::InSetOperation<K> inOp(keys);
359 impl::OutMapOperation<K, V> outOp(res);
361 impl.Get()->GetAll(inOp, outOp, err);
379 template<
typename InIter,
typename OutIter>
380 void GetAll(InIter begin, InIter end, OutIter dst)
384 impl::InIterOperation<K, V, InIter> inOp(begin, end);
385 impl::OutMapIterOperation<K, V, OutIter> outOp(dst);
387 impl.Get()->GetAll(inOp, outOp, err);
402 void Put(
const K& key,
const V& val)
424 impl::In2Operation<K, V> op(key, val);
426 impl.Get()->Put(op, err);
459 impl::InMapOperation<K, V> op(vals);
461 impl.Get()->PutAll(op, err);
477 template<
typename Iter>
482 impl::InIterOperation<K, V, Iter> op(begin, end);
484 impl.Get()->PutAll(op, err);
504 V res = GetAndPut(key, val, err);
527 impl::In2Operation<K, V> inOp(key, val);
528 impl::Out1Operation<V> outOp(oldVal);
530 impl.Get()->GetAndPut(inOp, outOp, err);
550 V res = GetAndReplace(key, val, err);
573 impl::In2Operation<K, V> inOp(key, val);
574 impl::Out1Operation<V> outOp(oldVal);
576 impl.Get()->GetAndReplace(inOp, outOp, err);
593 V res = GetAndRemove(key, err);
613 impl::In1Operation<K> inOp(key);
614 impl::Out1Operation<V> outOp(oldVal);
616 impl.Get()->GetAndRemove(inOp, outOp, err);
635 bool res = PutIfAbsent(key, val, err);
655 impl::In2Operation<K, V> op(key, val);
657 return impl.Get()->PutIfAbsent(op, err);
682 V res = GetAndPutIfAbsent(key, val, err);
712 impl::In2Operation<K, V> inOp(key, val);
713 impl::Out1Operation<V> outOp(oldVal);
715 impl.Get()->GetAndPutIfAbsent(inOp, outOp, err);
739 bool res = Replace(key, val, err);
764 impl::In2Operation<K, V> op(key, val);
766 return impl.Get()->Replace(op, err);
781 bool Replace(
const K& key,
const V& oldVal,
const V& newVal)
785 bool res = Replace(key, oldVal, newVal, err);
807 impl::In3Operation<K, V, V> op(key, oldVal, newVal);
809 return impl.Get()->ReplaceIfEqual(op, err);
826 LocalEvict(keys, err);
844 impl::InSetOperation<K> op(keys);
846 impl.Get()->LocalEvict(op, err);
860 template<
typename Iter>
865 impl::InIterOperation<K, V, Iter> op(begin, end);
867 impl.Get()->LocalEvict(op, err);
895 impl.Get()->Clear(err);
926 impl::In1Operation<K> op(key);
928 impl.Get()->Clear(op, err);
959 impl::InSetOperation<K> op(keys);
961 impl.Get()->ClearAll(op, err);
973 template<
typename Iter>
978 impl::InIterOperation<K, V, Iter> op(begin, end);
980 impl.Get()->ClearAll(op, err);
1000 LocalClear(key, err);
1019 impl::In1Operation<K> op(key);
1021 impl.Get()->LocalClear(op, err);
1039 LocalClearAll(keys, err);
1058 impl::InSetOperation<K> op(keys);
1060 impl.Get()->LocalClearAll(op, err);
1075 template<
typename Iter>
1080 impl::InIterOperation<K, V, Iter> op(begin, end);
1082 impl.Get()->LocalClearAll(op, err);
1106 bool res = Remove(key, err);
1131 impl::In1Operation<K> op(key);
1133 return impl.Get()->Remove(op, err);
1151 bool res = Remove(key, val, err);
1172 impl::In2Operation<K, V> op(key, val);
1174 return impl.Get()->RemoveIfEqual(op, err);
1190 RemoveAll(keys, err);
1207 impl::InSetOperation<K> op(keys);
1209 impl.Get()->RemoveAll(op, err);
1225 template<
typename Iter>
1230 impl::InIterOperation<K, V, Iter> op(begin, end);
1232 impl.Get()->RemoveAll(op, err);
1265 return impl.Get()->RemoveAll(err);
1305 int32_t res = LocalSize(peekModes, err);
1323 return impl.Get()->Size(peekModes,
true, err);
1366 int32_t res = Size(peekModes, err);
1385 return impl.Get()->Size(peekModes,
false, err);
1419 impl::cache::query::QueryCursorImpl* cursorImpl = impl.Get()->QuerySql(qry, err);
1454 impl::cache::query::QueryCursorImpl* cursorImpl = impl.Get()->QueryText(qry, err);
1489 impl::cache::query::QueryCursorImpl* cursorImpl = impl.Get()->QueryScan(qry, err);
1524 impl::cache::query::QueryCursorImpl* cursorImpl = impl.Get()->QuerySqlFields(qry, err);
1570 template<
typename R,
typename P,
typename A>
1571 R
Invoke(
const K& key,
const P& processor,
const A& arg)
1575 R res = Invoke<R>(key, processor, arg, err);
1625 template<
typename R,
typename P,
typename A>
1628 typedef impl::cache::CacheEntryProcessorHolder<P, A> ProcessorHolder;
1631 ProcessorHolder procHolder(processor, arg);
1633 impl::InCacheInvokeOperation<K, ProcessorHolder> inOp(key, procHolder);
1634 impl::Out1Operation<R> outOp(res);
1636 impl.Get()->Invoke(inOp, outOp, err);
1667 template<
typename R,
typename A>
1668 R
InvokeJava(
const K& key,
const std::string& processorName,
const A& arg)
1672 R res = InvokeJava<R>(key, processorName, arg, err);
1705 template<
typename R,
typename A>
1710 impl::In3Operation<std::string, K, A> inOp(processorName, key, arg);
1711 impl::Out1Operation<R> outOp(res);
1713 impl.Get()->InvokeJava(inOp, outOp, err);
1746 using namespace impl::cache::query::continuous;
1747 using namespace common::concurrent;
1749 const SharedPointer<ContinuousQueryImpl<K, V> >& qryImpl = qry.impl;
1751 if (!qryImpl.IsValid() || !qryImpl.Get()->HasListener())
1754 "Event listener is not set for ContinuousQuery instance");
1759 ContinuousQueryHandleImpl* cqImpl = impl.Get()->QueryContinuous(qryImpl, err);
1771 template<
typename Q>
1774 const Q& initialQry)
1793 template<
typename Q>
1798 using namespace impl::cache::query::continuous;
1799 using namespace common::concurrent;
1801 const SharedPointer<ContinuousQueryImpl<K, V> >& qryImpl = qry.impl;
1803 if (!qryImpl.IsValid() || !qryImpl.Get()->HasListener())
1806 "Event listener is not set for ContinuousQuery instance");
1811 ContinuousQueryHandleImpl* cqImpl = impl.Get()->QueryContinuous(qryImpl, initialQry, err);
1829 return impl.IsValid();
1839 impl.Get()->LoadCache(err);
1856 impl.Get()->LocalLoadCache(err);
1863 common::concurrent::SharedPointer<impl::cache::CacheImpl> impl;
1868 #endif //_IGNITE_CACHE_CACHE
void LocalEvict(const std::set< K > &keys)
Attempts to evict all entries associated with keys.
Definition: cache.h:822
V GetAndRemove(const K &key)
Atomically removes the entry for a key only if currently mapped to some value.
Definition: cache.h:589
Ignite API.
Definition: cache.h:47
V GetAndPutIfAbsent(const K &key, const V &val, IgniteError &err)
Stores given key-value pair in cache only if cache had no previous mapping for it.
Definition: cache.h:708
bool Replace(const K &key, const V &oldVal, const V &newVal)
Stores given key-value pair in cache only if the previous value is equal to the old value passed as a...
Definition: cache.h:781
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:631
void Clear(IgniteError &err)
Clear cache.
Definition: cache.h:893
bool ContainsKeys(const std::set< K > &keys, IgniteError &err)
Check if cache contains mapping for these keys.
Definition: cache.h:214
void PutAll(Iter begin, Iter end)
Stores given key-value pairs in cache.
Definition: cache.h:478
bool Remove(const K &key)
Removes given key mapping from cache.
Definition: cache.h:1102
void PutAll(const std::map< K, V > &vals, IgniteError &err)
Stores given key-value pairs in cache.
Definition: cache.h:457
bool Replace(const K &key, const V &val, IgniteError &err)
Stores given key-value pair in cache only if there is a previous mapping for it.
Definition: cache.h:762
V LocalPeek(const K &key, int32_t peekModes, IgniteError &err)
Peeks at cached value using optional set of peek modes.
Definition: cache.h:259
query::continuous::ContinuousQueryHandle< K, V > QueryContinuous(const query::continuous::ContinuousQuery< K, V > &qry)
Start continuous query execution.
Definition: cache.h:1724
bool Remove(const K &key, IgniteError &err)
Removes given key mapping from cache.
Definition: cache.h:1129
void LoadCache()
Executes LocalLoadCache on all cache nodes.
Definition: cache.h:1835
bool IsValid() const
Check if the instance is valid.
Definition: cache.h:1827
std::map< K, V > GetAll(const std::set< K > &keys, IgniteError &err)
Retrieves values mapped to the specified keys from cache.
Definition: cache.h:354
Main entry point for all Data Grid APIs.
Definition: cache.h:67
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:678
Scan query.
Definition: core/include/ignite/cache/query/query_scan.h:39
query::QueryCursor< K, V > Query(const query::TextQuery &qry)
Perform text query.
Definition: cache.h:1432
void ClearAll(const std::set< K > &keys)
Clear entries from the cache and swap storage, without notifying listeners or CacheWriters.
Definition: cache.h:939
void LocalLoadCache()
Loads state from the underlying persistent storage.
Definition: cache.h:1852
int32_t Size(int32_t peekModes)
Gets the number of all entries cached across all nodes.
Definition: cache.h:1362
V GetAndRemove(const K &key, IgniteError &err)
Atomically removes the entry for a key only if currently mapped to some value.
Definition: cache.h:609
V GetAndReplace(const K &key, const V &val, IgniteError &err)
Atomically replaces the value for a given key if and only if there is a value currently mapped by the...
Definition: cache.h:569
V GetAndPut(const K &key, const V &val, IgniteError &err)
Associates the specified value with the specified key in this cache, returning an existing value if o...
Definition: cache.h:523
int32_t Size(IgniteError &err)
Gets the number of all entries cached across all nodes.
Definition: cache.h:1348
int32_t LocalSize(IgniteError &err)
Gets the number of all entries cached on this node.
Definition: cache.h:1288
R InvokeJava(const K &key, const std::string &processorName, const A &arg, IgniteError &err)
Invokes an instance of Java class CacheEntryProcessor against the entry specified by the provided key...
Definition: cache.h:1706
void PutAll(const std::map< K, V > &vals)
Stores given key-value pairs in cache.
Definition: cache.h:438
Query cursor class template.
Definition: core/include/ignite/cache/query/query_cursor.h:53
query::QueryCursor< K, V > Query(const query::TextQuery &qry, IgniteError &err)
Perform text query.
Definition: cache.h:1452
query::QueryCursor< K, V > Query(const query::ScanQuery &qry, IgniteError &err)
Perform scan query.
Definition: cache.h:1487
query::QueryFieldsCursor Query(const query::SqlFieldsQuery &qry, IgniteError &err)
Perform sql fields query.
Definition: cache.h:1522
void GetAll(InIter begin, InIter end, OutIter dst)
Retrieves values mapped to the specified keys from cache.
Definition: cache.h:380
bool PutIfAbsent(const K &key, const V &val, IgniteError &err)
Atomically associates the specified key with the given value if it is not already associated with a v...
Definition: cache.h:653
V Get(const K &key)
Retrieves value mapped to the specified key from cache.
Definition: cache.h:283
void Put(const K &key, const V &val)
Associates the specified value with the specified key in the cache.
Definition: cache.h:402
const char * GetName() const
Get name of this cache (null for default cache).
Definition: cache.h:90
int32_t Size()
Gets the number of all entries cached across all nodes.
Definition: cache.h:1334
query::QueryFieldsCursor Query(const query::SqlFieldsQuery &qry)
Perform sql fields query.
Definition: cache.h:1502
void LocalEvict(const std::set< K > &keys, IgniteError &err)
Attempts to evict all entries associated with keys.
Definition: cache.h:842
void Put(const K &key, const V &val, IgniteError &err)
Associates the specified value with the specified key in the cache.
Definition: cache.h:422
void LocalEvict(Iter begin, Iter end)
Attempts to evict all entries associated with keys.
Definition: cache.h:861
Query fields cursor.
Definition: core/include/ignite/cache/query/query_fields_cursor.h:49
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:546
void LocalClearAll(Iter begin, Iter end)
Clear entries from the cache and swap storage, without notifying listeners or CacheWriters.
Definition: cache.h:1076
query::continuous::ContinuousQueryHandle< K, V > QueryContinuous(const query::continuous::ContinuousQuery< K, V > &qry, const Q &initialQry, IgniteError &err)
Start continuous query execution with the initial query.
Definition: cache.h:1794
bool Remove(const K &key, const V &val, IgniteError &err)
Removes given key mapping from cache if one exists and value is equal to the passed in value.
Definition: cache.h:1170
std::map< K, V > GetAll(const std::set< K > &keys)
Retrieves values mapped to the specified keys from cache.
Definition: cache.h:330
void ClearAll(Iter begin, Iter end)
Clear entries from the cache and swap storage, without notifying listeners or CacheWriters.
Definition: cache.h:974
Cache(impl::cache::CacheImpl *impl)
Constructor.
Definition: cache.h:77
void RemoveAll()
Removes all mappings from cache.
Definition: cache.h:1245
query::continuous::ContinuousQueryHandle< K, V > QueryContinuous(const query::continuous::ContinuousQuery< K, V > &qry, const Q &initialQry)
Start continuous query execution with the initial query.
Definition: cache.h:1772
query::QueryCursor< K, V > Query(const query::SqlQuery &qry, IgniteError &err)
Perform SQL query.
Definition: cache.h:1417
static const int IGNITE_ERR_GENERIC
Generic Ignite error.
Definition: ignite_error.h:130
void Clear()
Clear cache.
Definition: cache.h:877
Text query.
Definition: query_text.h:39
void LocalClear(const K &key, IgniteError &err)
Clear entry from the cache and swap storage, without notifying listeners or CacheWriters.
Definition: cache.h:1017
R Invoke(const K &key, const P &processor, const A &arg)
Invokes an CacheEntryProcessor against the MutableCacheEntry specified by the provided key.
Definition: cache.h:1571
int32_t LocalSize(int32_t peekModes)
Gets the number of all entries cached on this node.
Definition: cache.h:1301
void LocalClearAll(const std::set< K > &keys)
Clear entries from the cache and swap storage, without notifying listeners or CacheWriters.
Definition: cache.h:1035
void RemoveAll(const std::set< K > &keys)
Removes given key mappings from cache.
Definition: cache.h:1186
Continuous query.
Definition: continuous_query.h:58
bool ContainsKey(const K &key)
Check if cache contains mapping for this key.
Definition: cache.h:136
bool ContainsKeys(const std::set< K > &keys)
Check if cache contains mapping for these keys.
Definition: cache.h:171
void RemoveAll(Iter begin, Iter end)
Removes given key mappings from cache.
Definition: cache.h:1226
query::continuous::ContinuousQueryHandle< K, V > QueryContinuous(const query::continuous::ContinuousQuery< K, V > &qry, IgniteError &err)
Start continuous query execution.
Definition: cache.h:1743
query::QueryCursor< K, V > Query(const query::SqlQuery &qry)
Perform SQL query.
Definition: cache.h:1397
bool IsEmpty()
Checks whether this cache contains no key-value mappings.
Definition: cache.h:103
void Clear(const K &key, IgniteError &err)
Clear entry from the cache and swap storage, without notifying listeners or CacheWriters.
Definition: cache.h:924
bool IsEmpty(IgniteError &err)
Checks whether this cache contains no key-value mappings.
Definition: cache.h:123
void Clear(const K &key)
Clear entry from the cache and swap storage, without notifying listeners or CacheWriters.
Definition: cache.h:906
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:1147
void RemoveAll(IgniteError &err)
Removes all mappings from cache.
Definition: cache.h:1263
R InvokeJava(const K &key, const std::string &processorName, const A &arg)
Invokes an instance of Java class CacheEntryProcessor against the entry specified by the provided key...
Definition: cache.h:1668
static void ThrowIfNeeded(const IgniteError &err)
Throw an error if code is not IGNITE_SUCCESS.
Definition: ignite_error.cpp:26
int32_t LocalSize()
Gets the number of all entries cached on this node.
Definition: cache.h:1275
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:735
int32_t LocalSize(int32_t peekModes, IgniteError &err)
Gets the number of all entries cached on this node.
Definition: cache.h:1321
Sql fields query.
Definition: core/include/ignite/cache/query/query_sql_fields.h:41
query::QueryCursor< K, V > Query(const query::ScanQuery &qry)
Perform scan query.
Definition: cache.h:1467
int32_t Size(int32_t peekModes, IgniteError &err)
Gets the number of all entries cached across all nodes.
Definition: cache.h:1383
V Get(const K &key, IgniteError &err)
Retrieves value mapped to the specified key from cache.
Definition: cache.h:307
bool ContainsKeys(InputIter begin, InputIter end)
Check if cache contains mapping for these keys.
Definition: cache.h:192
V LocalPeek(const K &key, int32_t peekModes)
Peeks at cached value using optional set of peek modes.
Definition: cache.h:234
Ignite error information.
Definition: ignite_error.h:93
Sql query.
Definition: query_sql.h:43
bool Replace(const K &key, const V &oldVal, const V &newVal, IgniteError &err)
Stores given key-value pair in cache only if the previous value is equal to the old value passed as a...
Definition: cache.h:805
bool ContainsKey(const K &key, IgniteError &err)
Check if cache contains mapping for this key.
Definition: cache.h:156
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:500
void LocalClear(const K &key)
Clear entry from the cache and swap storage, without notifying listeners or CacheWriters.
Definition: cache.h:996
void LocalClearAll(const std::set< K > &keys, IgniteError &err)
Clear entries from the cache and swap storage, without notifying listeners or CacheWriters.
Definition: cache.h:1056
void RemoveAll(const std::set< K > &keys, IgniteError &err)
Removes given key mappings from cache.
Definition: cache.h:1205
void ClearAll(const std::set< K > &keys, IgniteError &err)
Clear entries from the cache and swap storage, without notifying listeners or CacheWriters.
Definition: cache.h:957
R Invoke(const K &key, const P &processor, const A &arg, IgniteError &err)
Invokes an CacheEntryProcessor against the MutableCacheEntry specified by the provided key.
Definition: cache.h:1626
@ ALL
Peeks into all available cache storages.
Definition: core/include/ignite/cache/cache_peek_mode.h:39
Continuous query handle.
Definition: core/include/ignite/cache/query/continuous/continuous_query_handle.h:39