23 #ifndef _IGNITE_CACHE_CACHE 24 #define _IGNITE_CACHE_CACHE 29 #include <ignite/common/common.h> 30 #include <ignite/common/concurrent.h> 42 #include <ignite/impl/cache/cache_impl.h> 43 #include <ignite/impl/cache/cache_entry_processor_holder.h> 44 #include <ignite/impl/operations.h> 45 #include <ignite/impl/module_manager.h> 67 template<
typename K,
typename V>
68 class IGNITE_IMPORT_EXPORT
Cache 78 Cache(impl::cache::CacheImpl* impl) :
93 return impl.Get()->GetName();
108 bool res = IsEmpty(err);
126 return Size(err) == 0;
141 bool res = ContainsKey(key, err);
159 impl::In1Operation<K> op(key);
161 return impl.Get()->ContainsKey(op, err);
176 bool res = ContainsKeys(keys, err);
192 template<
typename InputIter>
197 impl::InIterOperation<K, V, InputIter> op(begin, end);
199 bool res = impl.Get()->ContainsKeys(op, err);
217 impl::InSetOperation<K> op(keys);
219 return impl.Get()->ContainsKeys(op, err);
239 V res = LocalPeek(key, peekModes, err);
264 impl::InCacheLocalPeekOperation<K> inOp(key, peekModes);
265 impl::Out1Operation<V> outOp(val);
267 impl.Get()->LocalPeek(inOp, outOp, peekModes, err);
288 V res = Get(key, err);
311 impl::In1Operation<K> inOp(key);
312 impl::Out1Operation<V> outOp(val);
314 impl.Get()->Get(inOp, outOp, err);
331 std::map<K, V>
GetAll(
const std::set<K>& keys)
335 std::map<K, V> res = GetAll(keys, err);
359 impl::InSetOperation<K> inOp(keys);
360 impl::OutMapOperation<K, V> outOp(res);
362 impl.Get()->GetAll(inOp, outOp, err);
380 template<
typename InIter,
typename OutIter>
381 void GetAll(InIter begin, InIter end, OutIter dst)
385 impl::InIterOperation<K, V, InIter> inOp(begin, end);
386 impl::OutMapIterOperation<K, V, OutIter> outOp(dst);
388 impl.Get()->GetAll(inOp, outOp, err);
403 void Put(
const K& key,
const V& val)
425 impl::In2Operation<K, V> op(key, val);
427 impl.Get()->Put(op, err);
460 impl::InMapOperation<K, V> op(vals);
462 impl.Get()->PutAll(op, err);
475 template<
typename Iter>
480 impl::InIterOperation<K, V, Iter> op(begin, end);
482 impl.Get()->PutAll(op, err);
502 V res = GetAndPut(key, val, err);
525 impl::In2Operation<K, V> inOp(key, val);
526 impl::Out1Operation<V> outOp(oldVal);
528 impl.Get()->GetAndPut(inOp, outOp, err);
548 V res = GetAndReplace(key, val, err);
571 impl::In2Operation<K, V> inOp(key, val);
572 impl::Out1Operation<V> outOp(oldVal);
574 impl.Get()->GetAndReplace(inOp, outOp, err);
591 V res = GetAndRemove(key, err);
611 impl::In1Operation<K> inOp(key);
612 impl::Out1Operation<V> outOp(oldVal);
614 impl.Get()->GetAndRemove(inOp, outOp, err);
633 bool res = PutIfAbsent(key, val, err);
653 impl::In2Operation<K, V> op(key, val);
655 return impl.Get()->PutIfAbsent(op, err);
680 V res = GetAndPutIfAbsent(key, val, err);
710 impl::In2Operation<K, V> inOp(key, val);
711 impl::Out1Operation<V> outOp(oldVal);
713 impl.Get()->GetAndPutIfAbsent(inOp, outOp, err);
737 bool res = Replace(key, val, err);
762 impl::In2Operation<K, V> op(key, val);
764 return impl.Get()->Replace(op, err);
779 bool Replace(
const K& key,
const V& oldVal,
const V& newVal)
783 bool res = Replace(key, oldVal, newVal, err);
805 impl::In3Operation<K, V, V> op(key, oldVal, newVal);
807 return impl.Get()->ReplaceIfEqual(op, err);
824 LocalEvict(keys, err);
842 impl::InSetOperation<K> op(keys);
844 impl.Get()->LocalEvict(op, err);
858 template<
typename Iter>
863 impl::InIterOperation<K, V, Iter> op(begin, end);
865 impl.Get()->LocalEvict(op, err);
893 impl.Get()->Clear(err);
924 impl::In1Operation<K> op(key);
926 impl.Get()->Clear(op, err);
957 impl::InSetOperation<K> op(keys);
959 impl.Get()->ClearAll(op, err);
971 template<
typename Iter>
976 impl::InIterOperation<K, V, Iter> op(begin, end);
978 impl.Get()->ClearAll(op, err);
998 LocalClear(key, err);
1017 impl::In1Operation<K> op(key);
1019 impl.Get()->LocalClear(op, err);
1037 LocalClearAll(keys, err);
1056 impl::InSetOperation<K> op(keys);
1058 impl.Get()->LocalClearAll(op, err);
1073 template<
typename Iter>
1078 impl::InIterOperation<K, V, Iter> op(begin, end);
1080 impl.Get()->LocalClearAll(op, err);
1104 bool res = Remove(key, err);
1129 impl::In1Operation<K> op(key);
1131 return impl.Get()->Remove(op, err);
1149 bool res = Remove(key, val, err);
1170 impl::In2Operation<K, V> op(key, val);
1172 return impl.Get()->RemoveIfEqual(op, err);
1188 RemoveAll(keys, err);
1205 impl::InSetOperation<K> op(keys);
1207 impl.Get()->RemoveAll(op, err);
1220 template<
typename Iter>
1225 impl::InIterOperation<K, V, Iter> op(begin, end);
1227 impl.Get()->RemoveAll(op, err);
1260 return impl.Get()->RemoveAll(err);
1300 int32_t res = LocalSize(peekModes, err);
1318 return impl.Get()->Size(peekModes,
true, err);
1361 int32_t res = Size(peekModes, err);
1380 return impl.Get()->Size(peekModes,
false, err);
1413 impl::cache::query::QueryCursorImpl* cursorImpl = impl.Get()->QuerySql(qry, err);
1448 impl::cache::query::QueryCursorImpl* cursorImpl = impl.Get()->QueryText(qry, err);
1483 impl::cache::query::QueryCursorImpl* cursorImpl = impl.Get()->QueryScan(qry, err);
1518 impl::cache::query::QueryCursorImpl* cursorImpl = impl.Get()->QuerySqlFields(qry, err);
1564 template<
typename R,
typename P,
typename A>
1565 R
Invoke(
const K& key,
const P& processor,
const A& arg)
1569 R res = Invoke<R>(key, processor, arg, err);
1618 template<
typename R,
typename P,
typename A>
1621 typedef impl::cache::CacheEntryProcessorHolder<P, A> ProcessorHolder;
1624 ProcessorHolder procHolder(processor, arg);
1626 impl::In2Operation<K, ProcessorHolder> inOp(key, procHolder);
1627 impl::Out1Operation<R> outOp(res);
1629 impl.Get()->Invoke(inOp, outOp, err);
1662 using namespace impl::cache::query::continuous;
1663 using namespace common::concurrent;
1665 const SharedPointer<ContinuousQueryImpl<K, V> >& qryImpl = qry.impl;
1667 if (!qryImpl.IsValid() || !qryImpl.Get()->HasListener())
1670 "Event listener is not set for ContinuousQuery instance");
1675 ContinuousQueryHandleImpl* cqImpl = impl.Get()->QueryContinuous(qryImpl, err);
1687 template<
typename Q>
1690 const Q& initialQry)
1709 template<
typename Q>
1714 using namespace impl::cache::query::continuous;
1715 using namespace common::concurrent;
1717 const SharedPointer<ContinuousQueryImpl<K, V> >& qryImpl = qry.impl;
1719 if (!qryImpl.IsValid() || !qryImpl.Get()->HasListener())
1722 "Event listener is not set for ContinuousQuery instance");
1727 ContinuousQueryHandleImpl* cqImpl = impl.Get()->QueryContinuous(qryImpl, initialQry, err);
1745 return impl.IsValid();
1755 impl.Get()->LoadCache(err);
1772 impl.Get()->LocalLoadCache(err);
1779 common::concurrent::SharedPointer<impl::cache::CacheImpl> impl;
1784 #endif //_IGNITE_CACHE_CACHE 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:1688
query::QueryCursor< K, V > Query(const query::TextQuery &qry)
Perform text query.
Definition: cache.h:1426
void ClearAll(const std::set< K > &keys)
Clear entries from the cache and swap storage, without notifying listeners or CacheWriters.
Definition: cache.h:937
Text query.
Definition: query_text.h:40
void Clear()
Clear cache.
Definition: cache.h:875
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:521
query::continuous::ContinuousQueryHandle< K, V > QueryContinuous(const query::continuous::ContinuousQuery< K, V > &qry, IgniteError &err)
Start continuous query execution.
Definition: cache.h:1659
int32_t LocalSize(int32_t peekModes)
Gets the number of all entries cached on this node.
Definition: cache.h:1296
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:1054
Declares ignite::cache::query::QueryCursor class template.
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:1619
void GetAll(InIter begin, InIter end, OutIter dst)
Retrieves values mapped to the specified keys from cache.
Definition: cache.h:381
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:1145
Declares ignite::cache::query::QueryFieldsCursor class.
Declares ignite::cache::query::SqlQuery class.
void Clear(const K &key)
Clear entry from the cache and swap storage, without notifying listeners or CacheWriters.
Definition: cache.h:904
Main entry point for all Data Grid APIs.
Definition: cache.h:68
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:1168
int32_t Size()
Gets the number of all entries cached across all nodes.
Definition: cache.h:1329
bool ContainsKeys(const std::set< K > &keys)
Check if cache contains mapping for these keys.
Definition: cache.h:172
void LocalClearAll(Iter begin, Iter end)
Clear entries from the cache and swap storage, without notifying listeners or CacheWriters.
Definition: cache.h:1074
query::QueryCursor< K, V > Query(const query::SqlQuery &qry)
Perform SQL query.
Definition: cache.h:1391
void Clear(const K &key, IgniteError &err)
Clear entry from the cache and swap storage, without notifying listeners or CacheWriters.
Definition: cache.h:922
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:706
Cache(impl::cache::CacheImpl *impl)
Constructor.
Definition: cache.h:78
bool Remove(const K &key)
Removes given key mapping from cache.
Definition: cache.h:1100
bool IsEmpty(IgniteError &err)
Checks whether this cache contains no key-value mappings.
Definition: cache.h:124
Continuous query.
Definition: continuous_query.h:58
void Clear(IgniteError &err)
Clear cache.
Definition: cache.h:891
query::continuous::ContinuousQueryHandle< K, V > QueryContinuous(const query::continuous::ContinuousQuery< K, V > &qry)
Start continuous query execution.
Definition: cache.h:1640
Declares ignite::cache::CachePeekMode enum.
bool ContainsKeys(const std::set< K > &keys, IgniteError &err)
Check if cache contains mapping for these keys.
Definition: cache.h:215
void PutAll(Iter begin, Iter end)
Stores given key-value pairs in cache.
Definition: cache.h:476
V Get(const K &key, IgniteError &err)
Retrieves value mapped to the specified key from cache.
Definition: cache.h:308
void RemoveAll()
Removes all mappings from cache.
Definition: cache.h:1240
Scan query.
Definition: query_scan.h:40
Sql query.
Definition: query_sql.h:42
query::QueryCursor< K, V > Query(const query::ScanQuery &qry)
Perform scan query.
Definition: cache.h:1461
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:1565
query::QueryCursor< K, V > Query(const query::SqlQuery &qry, IgniteError &err)
Perform SQL query.
Definition: cache.h:1411
V GetAndRemove(const K &key, IgniteError &err)
Atomically removes the entry for a key only if currently mapped to some value.
Definition: cache.h:607
V LocalPeek(const K &key, int32_t peekModes)
Peeks at cached value using optional set of peek modes.
Definition: cache.h:235
void RemoveAll(const std::set< K > &keys)
Removes given key mappings from cache.
Definition: cache.h:1184
bool Replace(const K &key, const V &oldVal, const V &newVal, IgniteError &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:803
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:955
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:498
Sql fields query.
Definition: query_sql_fields.h:42
bool ContainsKey(const K &key)
Check if cache contains mapping for this key.
Definition: cache.h:137
Peeks into all available cache storages.
Definition: core/include/ignite/cache/cache_peek_mode.h:40
void LocalClear(const K &key)
Clear entry from the cache and swap storage, without notifying listeners or CacheWriters.
Definition: cache.h:994
int32_t Size(IgniteError &err)
Gets the number of all entries cached across all nodes.
Definition: cache.h:1343
bool IsEmpty()
Checks whether this cache contains no key-value mappings.
Definition: cache.h:104
Continuous query handle.
Definition: continuous_query_handle.h:40
void RemoveAll(const std::set< K > &keys, IgniteError &err)
Removes given key mappings from cache.
Definition: cache.h:1203
void PutAll(const std::map< K, V > &vals)
Stores given key-value pairs in cache.
Definition: cache.h:439
void LocalEvict(const std::set< K > &keys, IgniteError &err)
Attempts to evict all entries associated with keys.
Definition: cache.h:840
V GetAndRemove(const K &key)
Atomically removes the entry for a key only if currently mapped to some value.
Definition: cache.h:587
Query fields cursor.
Definition: query_fields_cursor.h:50
V Get(const K &key)
Retrieves value mapped to the specified key from cache.
Definition: cache.h:284
void Put(const K &key, const V &val)
Associates the specified value with the specified key in the cache.
Definition: cache.h:403
void LocalEvict(const std::set< K > &keys)
Attempts to evict all entries associated with keys.
Definition: cache.h:820
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:1710
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:779
Declares ignite::cache::query::continuous::ContinuousQueryHandle class.
void LoadCache()
Executes LocalLoadCache on all cache nodes.
Definition: cache.h:1751
int32_t Size(int32_t peekModes, IgniteError &err)
Gets the number of all entries cached across all nodes.
Definition: cache.h:1378
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:629
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:760
int32_t Size(int32_t peekModes)
Gets the number of all entries cached across all nodes.
Definition: cache.h:1357
std::map< K, V > GetAll(const std::set< K > &keys)
Retrieves values mapped to the specified keys from cache.
Definition: cache.h:331
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:567
bool ContainsKey(const K &key, IgniteError &err)
Check if cache contains mapping for this key.
Definition: cache.h:157
void PutAll(const std::map< K, V > &vals, IgniteError &err)
Stores given key-value pairs in cache.
Definition: cache.h:458
Declares ignite::cache::query::continuous::ContinuousQuery class.
V LocalPeek(const K &key, int32_t peekModes, IgniteError &err)
Peeks at cached value using optional set of peek modes.
Definition: cache.h:260
int32_t LocalSize(IgniteError &err)
Gets the number of all entries cached on this node.
Definition: cache.h:1283
Declares ignite::cache::query::SqlFieldsQuery class.
Ignite error information.
Definition: ignite_error.h:94
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:676
void LocalClearAll(const std::set< K > &keys)
Clear entries from the cache and swap storage, without notifying listeners or CacheWriters.
Definition: cache.h:1033
Declares ignite::cache::query::ScanQuery class.
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:651
void Put(const K &key, const V &val, IgniteError &err)
Associates the specified value with the specified key in the cache.
Definition: cache.h:423
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:544
void RemoveAll(Iter begin, Iter end)
Removes given key mappings from cache.
Definition: cache.h:1221
const char * GetName() const
Get name of this cache (null for default cache).
Definition: cache.h:91
query::QueryCursor< K, V > Query(const query::ScanQuery &qry, IgniteError &err)
Perform scan query.
Definition: cache.h:1481
void LocalEvict(Iter begin, Iter end)
Attempts to evict all entries associated with keys.
Definition: cache.h:859
Apache Ignite API.
Definition: cache.h:48
query::QueryCursor< K, V > Query(const query::TextQuery &qry, IgniteError &err)
Perform text query.
Definition: cache.h:1446
Declares ignite::IgniteError class.
query::QueryFieldsCursor Query(const query::SqlFieldsQuery &qry, IgniteError &err)
Perform sql fields query.
Definition: cache.h:1516
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:733
query::QueryFieldsCursor Query(const query::SqlFieldsQuery &qry)
Perform sql fields query.
Definition: cache.h:1496
Query cursor class template.
Definition: query_cursor.h:54
static void ThrowIfNeeded(const IgniteError &err)
Throw an error if code is not IGNITE_SUCCESS.
Definition: ignite_error.cpp:27
void RemoveAll(IgniteError &err)
Removes all mappings from cache.
Definition: cache.h:1258
void ClearAll(Iter begin, Iter end)
Clear entries from the cache and swap storage, without notifying listeners or CacheWriters.
Definition: cache.h:972
std::map< K, V > GetAll(const std::set< K > &keys, IgniteError &err)
Retrieves values mapped to the specified keys from cache.
Definition: cache.h:355
int32_t LocalSize()
Gets the number of all entries cached on this node.
Definition: cache.h:1270
static const int IGNITE_ERR_GENERIC
Generic Ignite error.
Definition: ignite_error.h:131
void LocalLoadCache()
Loads state from the underlying persistent storage.
Definition: cache.h:1768
bool Remove(const K &key, IgniteError &err)
Removes given key mapping from cache.
Definition: cache.h:1127
void LocalClear(const K &key, IgniteError &err)
Clear entry from the cache and swap storage, without notifying listeners or CacheWriters.
Definition: cache.h:1015
Declares ignite::cache::query::TextQuery class.
int32_t LocalSize(int32_t peekModes, IgniteError &err)
Gets the number of all entries cached on this node.
Definition: cache.h:1316
bool IsValid() const
Check if the instance is valid.
Definition: cache.h:1743
bool ContainsKeys(InputIter begin, InputIter end)
Check if cache contains mapping for these keys.
Definition: cache.h:193