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);
262 impl::InCacheLocalPeekOperation<K> inOp(key, peekModes);
263 impl::Out1Operation<V> outOp;
265 impl.Get()->LocalPeek(inOp, outOp, peekModes, err);
267 return outOp.GetResult();
286 V res = Get(key, err);
308 impl::In1Operation<K> inOp(key);
309 impl::Out1Operation<V> outOp;
311 impl.Get()->Get(inOp, outOp, err);
313 return outOp.GetResult();
328 std::map<K, V>
GetAll(
const std::set<K>& keys)
332 std::map<K, V> res = GetAll(keys, err);
354 impl::InSetOperation<K> inOp(keys);
355 impl::OutMapOperation<K, V> outOp;
357 impl.Get()->GetAll(inOp, outOp, err);
359 return outOp.GetResult();
375 template<
typename InIter,
typename OutIter>
376 void GetAll(InIter begin, InIter end, OutIter dst)
380 impl::InIterOperation<K, V, InIter> inOp(begin, end);
381 impl::OutMapIterOperation<K, V, OutIter> outOp(dst);
383 impl.Get()->GetAll(inOp, outOp, err);
398 void Put(
const K& key,
const V& val)
420 impl::In2Operation<K, V> op(key, val);
422 impl.Get()->Put(op, err);
455 impl::InMapOperation<K, V> op(vals);
457 impl.Get()->PutAll(op, err);
470 template<
typename Iter>
475 impl::InIterOperation<K, V, Iter> op(begin, end);
477 impl.Get()->PutAll(op, err);
497 V res = GetAndPut(key, val, err);
518 impl::In2Operation<K, V> inOp(key, val);
519 impl::Out1Operation<V> outOp;
521 impl.Get()->GetAndPut(inOp, outOp, err);
523 return outOp.GetResult();
541 V res = GetAndReplace(key, val, err);
562 impl::In2Operation<K, V> inOp(key, val);
563 impl::Out1Operation<V> outOp;
565 impl.Get()->GetAndReplace(inOp, outOp, err);
567 return outOp.GetResult();
582 V res = GetAndRemove(key, err);
600 impl::In1Operation<K> inOp(key);
601 impl::Out1Operation<V> outOp;
603 impl.Get()->GetAndRemove(inOp, outOp, err);
605 return outOp.GetResult();
622 bool res = PutIfAbsent(key, val, err);
642 impl::In2Operation<K, V> op(key, val);
644 return impl.Get()->PutIfAbsent(op, err);
669 V res = GetAndPutIfAbsent(key, val, err);
697 impl::In2Operation<K, V> inOp(key, val);
698 impl::Out1Operation<V> outOp;
700 impl.Get()->GetAndPutIfAbsent(inOp, outOp, err);
702 return outOp.GetResult();
724 bool res = Replace(key, val, err);
749 impl::In2Operation<K, V> op(key, val);
751 return impl.Get()->Replace(op, err);
766 bool Replace(
const K& key,
const V& oldVal,
const V& newVal)
770 bool res = Replace(key, oldVal, newVal, err);
792 impl::In3Operation<K, V, V> op(key, oldVal, newVal);
794 return impl.Get()->ReplaceIfEqual(op, err);
811 LocalEvict(keys, err);
829 impl::InSetOperation<K> op(keys);
831 impl.Get()->LocalEvict(op, err);
845 template<
typename Iter>
850 impl::InIterOperation<K, V, Iter> op(begin, end);
852 impl.Get()->LocalEvict(op, err);
880 impl.Get()->Clear(err);
911 impl::In1Operation<K> op(key);
913 impl.Get()->Clear(op, err);
944 impl::InSetOperation<K> op(keys);
946 impl.Get()->ClearAll(op, err);
958 template<
typename Iter>
963 impl::InIterOperation<K, V, Iter> op(begin, end);
965 impl.Get()->ClearAll(op, err);
985 LocalClear(key, err);
1004 impl::In1Operation<K> op(key);
1006 impl.Get()->LocalClear(op, err);
1024 LocalClearAll(keys, err);
1043 impl::InSetOperation<K> op(keys);
1045 impl.Get()->LocalClearAll(op, err);
1060 template<
typename Iter>
1065 impl::InIterOperation<K, V, Iter> op(begin, end);
1067 impl.Get()->LocalClearAll(op, err);
1091 bool res = Remove(key, err);
1116 impl::In1Operation<K> op(key);
1118 return impl.Get()->Remove(op, err);
1136 bool res = Remove(key, val, err);
1157 impl::In2Operation<K, V> op(key, val);
1159 return impl.Get()->RemoveIfEqual(op, err);
1175 RemoveAll(keys, err);
1192 impl::InSetOperation<K> op(keys);
1194 impl.Get()->RemoveAll(op, err);
1207 template<
typename Iter>
1212 impl::InIterOperation<K, V, Iter> op(begin, end);
1214 impl.Get()->RemoveAll(op, err);
1247 return impl.Get()->RemoveAll(err);
1287 int32_t res = LocalSize(peekModes, err);
1305 return impl.Get()->Size(peekModes,
true, err);
1348 int32_t res = Size(peekModes, err);
1367 return impl.Get()->Size(peekModes,
false, err);
1400 impl::cache::query::QueryCursorImpl* cursorImpl = impl.Get()->QuerySql(qry, err);
1435 impl::cache::query::QueryCursorImpl* cursorImpl = impl.Get()->QueryText(qry, err);
1470 impl::cache::query::QueryCursorImpl* cursorImpl = impl.Get()->QueryScan(qry, err);
1505 impl::cache::query::QueryCursorImpl* cursorImpl = impl.Get()->QuerySqlFields(qry, err);
1551 template<
typename R,
typename P,
typename A>
1552 R
Invoke(
const K& key,
const P& processor,
const A& arg)
1556 R res = Invoke<R>(key, processor, arg, err);
1605 template<
typename R,
typename P,
typename A>
1608 typedef impl::cache::CacheEntryProcessorHolder<P, A> ProcessorHolder;
1610 ProcessorHolder procHolder(processor, arg);
1612 impl::In2Operation<K, ProcessorHolder> inOp(key, procHolder);
1613 impl::Out1Operation<R> outOp;
1615 impl.Get()->Invoke(inOp, outOp, err);
1617 return outOp.GetResult();
1648 using namespace impl::cache::query::continuous;
1649 using namespace common::concurrent;
1651 const SharedPointer<ContinuousQueryImpl<K, V> >& qryImpl = qry.impl;
1653 if (!qryImpl.IsValid() || !qryImpl.Get()->HasListener())
1656 "Event listener is not set for ContinuousQuery instance");
1661 ContinuousQueryHandleImpl* cqImpl = impl.Get()->QueryContinuous(qryImpl, err);
1673 template<
typename Q>
1676 const Q& initialQry)
1695 template<
typename Q>
1700 using namespace impl::cache::query::continuous;
1701 using namespace common::concurrent;
1703 const SharedPointer<ContinuousQueryImpl<K, V> >& qryImpl = qry.impl;
1705 if (!qryImpl.IsValid() || !qryImpl.Get()->HasListener())
1708 "Event listener is not set for ContinuousQuery instance");
1713 ContinuousQueryHandleImpl* cqImpl = impl.Get()->QueryContinuous(qryImpl, initialQry, err);
1731 return impl.IsValid();
1741 impl.Get()->LoadCache(err);
1758 impl.Get()->LocalLoadCache(err);
1765 common::concurrent::SharedPointer<impl::cache::CacheImpl> impl;
1770 #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:1674
const char * GetName() const
Get name of this cache (null for default cache).
Definition: cache.h:91
query::QueryCursor< K, V > Query(const query::TextQuery &qry)
Perform text query.
Definition: cache.h:1413
void ClearAll(const std::set< K > &keys)
Clear entries from the cache and swap storage, without notifying listeners or CacheWriters.
Definition: cache.h:924
Text query.
Definition: query_text.h:40
void Clear()
Clear cache.
Definition: cache.h:862
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:516
query::continuous::ContinuousQueryHandle< K, V > QueryContinuous(const query::continuous::ContinuousQuery< K, V > &qry, IgniteError &err)
Start continuous query execution.
Definition: cache.h:1645
int32_t LocalSize(int32_t peekModes)
Gets the number of all entries cached on this node.
Definition: cache.h:1283
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:1041
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:1606
void GetAll(InIter begin, InIter end, OutIter dst)
Retrieves values mapped to the specified keys from cache.
Definition: cache.h:376
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:1132
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:891
Main entry point for all Data Grid APIs.
Definition: cache.h:68
Declares ignite::cache::CachePeekMode enum.
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:1155
int32_t Size()
Gets the number of all entries cached across all nodes.
Definition: cache.h:1316
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:1061
query::QueryCursor< K, V > Query(const query::SqlQuery &qry)
Perform SQL query.
Definition: cache.h:1378
void Clear(const K &key, IgniteError &err)
Clear entry from the cache and swap storage, without notifying listeners or CacheWriters.
Definition: cache.h:909
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:695
Cache(impl::cache::CacheImpl *impl)
Constructor.
Definition: cache.h:78
bool Remove(const K &key)
Removes given key mapping from cache.
Definition: cache.h:1087
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:878
query::continuous::ContinuousQueryHandle< K, V > QueryContinuous(const query::continuous::ContinuousQuery< K, V > &qry)
Start continuous query execution.
Definition: cache.h:1626
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:471
V Get(const K &key, IgniteError &err)
Retrieves value mapped to the specified key from cache.
Definition: cache.h:306
void RemoveAll()
Removes all mappings from cache.
Definition: cache.h:1227
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:1448
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:1552
query::QueryCursor< K, V > Query(const query::SqlQuery &qry, IgniteError &err)
Perform SQL query.
Definition: cache.h:1398
V GetAndRemove(const K &key, IgniteError &err)
Atomically removes the entry for a key only if currently mapped to some value.
Definition: cache.h:598
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:1171
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:790
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:942
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:493
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: 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:981
int32_t Size(IgniteError &err)
Gets the number of all entries cached across all nodes.
Definition: cache.h:1330
bool IsEmpty()
Checks whether this cache contains no key-value mappings.
Definition: cache.h:104
bool IsValid() const
Check if the instance is valid.
Definition: cache.h:1729
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:1190
void PutAll(const std::map< K, V > &vals)
Stores given key-value pairs in cache.
Definition: cache.h:434
void LocalEvict(const std::set< K > &keys, IgniteError &err)
Attempts to evict all entries associated with keys.
Definition: cache.h:827
V GetAndRemove(const K &key)
Atomically removes the entry for a key only if currently mapped to some value.
Definition: cache.h:578
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:282
void Put(const K &key, const V &val)
Associates the specified value with the specified key in the cache.
Definition: cache.h:398
void LocalEvict(const std::set< K > &keys)
Attempts to evict all entries associated with keys.
Definition: cache.h:807
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:1696
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:766
Declares ignite::cache::query::continuous::ContinuousQueryHandle class.
void LoadCache()
Executes LocalLoadCache on all cache nodes.
Definition: cache.h:1737
int32_t Size(int32_t peekModes, IgniteError &err)
Gets the number of all entries cached across all nodes.
Definition: cache.h:1365
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:618
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:747
int32_t Size(int32_t peekModes)
Gets the number of all entries cached across all nodes.
Definition: cache.h:1344
std::map< K, V > GetAll(const std::set< K > &keys)
Retrieves values mapped to the specified keys from cache.
Definition: cache.h:328
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:560
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:453
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:1270
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:665
void LocalClearAll(const std::set< K > &keys)
Clear entries from the cache and swap storage, without notifying listeners or CacheWriters.
Definition: cache.h:1020
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:640
void Put(const K &key, const V &val, IgniteError &err)
Associates the specified value with the specified key in the cache.
Definition: cache.h:418
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:537
void RemoveAll(Iter begin, Iter end)
Removes given key mappings from cache.
Definition: cache.h:1208
query::QueryCursor< K, V > Query(const query::ScanQuery &qry, IgniteError &err)
Perform scan query.
Definition: cache.h:1468
void LocalEvict(Iter begin, Iter end)
Attempts to evict all entries associated with keys.
Definition: cache.h:846
Apache Ignite API.
Definition: cache.h:48
query::QueryCursor< K, V > Query(const query::TextQuery &qry, IgniteError &err)
Perform text query.
Definition: cache.h:1433
Declares ignite::IgniteError class.
query::QueryFieldsCursor Query(const query::SqlFieldsQuery &qry, IgniteError &err)
Perform sql fields query.
Definition: cache.h:1503
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:720
query::QueryFieldsCursor Query(const query::SqlFieldsQuery &qry)
Perform sql fields query.
Definition: cache.h:1483
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:1245
void ClearAll(Iter begin, Iter end)
Clear entries from the cache and swap storage, without notifying listeners or CacheWriters.
Definition: cache.h:959
std::map< K, V > GetAll(const std::set< K > &keys, IgniteError &err)
Retrieves values mapped to the specified keys from cache.
Definition: cache.h:352
int32_t LocalSize()
Gets the number of all entries cached on this node.
Definition: cache.h:1257
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:1754
bool Remove(const K &key, IgniteError &err)
Removes given key mapping from cache.
Definition: cache.h:1114
void LocalClear(const K &key, IgniteError &err)
Clear entry from the cache and swap storage, without notifying listeners or CacheWriters.
Definition: cache.h:1002
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:1303
bool ContainsKeys(InputIter begin, InputIter end)
Check if cache contains mapping for these keys.
Definition: cache.h:193