Apache Ignite C++
cache.h
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
23 #ifndef _IGNITE_CACHE_CACHE
24 #define _IGNITE_CACHE_CACHE
25 
26 #include <map>
27 #include <set>
28 
29 #include <ignite/common/common.h>
30 #include <ignite/common/concurrent.h>
31 #include <ignite/ignite_error.h>
32 
40 #include "ignite/impl/cache/cache_impl.h"
41 #include "ignite/impl/operations.h"
42 
43 namespace ignite
44 {
45  namespace cache
46  {
59  template<typename K, typename V>
60  class IGNITE_IMPORT_EXPORT Cache
61  {
62  public:
70  Cache(impl::cache::CacheImpl* impl) :
71  impl(impl)
72  {
73  // No-op.
74  }
75 
83  const char* GetName() const
84  {
85  return impl.Get()->GetName();
86  }
87 
96  bool IsEmpty()
97  {
98  IgniteError err;
99 
100  bool res = IsEmpty(err);
101 
103 
104  return res;
105  }
106 
116  bool IsEmpty(IgniteError& err)
117  {
118  return impl.Get()->IsEmpty(&err);
119  }
120 
129  bool ContainsKey(const K& key)
130  {
131  IgniteError err;
132 
133  bool res = ContainsKey(key, err);
134 
136 
137  return res;
138  }
139 
149  bool ContainsKey(const K& key, IgniteError& err)
150  {
151  impl::In1Operation<K> op(&key);
152 
153  return impl.Get()->ContainsKey(op, &err);
154  }
155 
164  bool ContainsKeys(const std::set<K>& keys)
165  {
166  IgniteError err;
167 
168  bool res = ContainsKeys(keys, err);
169 
171 
172  return res;
173  }
174 
184  bool ContainsKeys(const std::set<K>& keys, IgniteError& err)
185  {
186  impl::InSetOperation<K> op(&keys);
187 
188  return impl.Get()->ContainsKeys(op, &err);
189  }
190 
204  V LocalPeek(const K& key, int32_t peekModes)
205  {
206  IgniteError err;
207 
208  V res = LocalPeek(key, peekModes, err);
209 
211 
212  return res;
213  }
214 
229  V LocalPeek(const K& key, int32_t peekModes, IgniteError& err)
230  {
231  impl::InCacheLocalPeekOperation<K> inOp(&key, peekModes);
232  impl::Out1Operation<V> outOp;
233 
234  impl.Get()->LocalPeek(inOp, outOp, peekModes, &err);
235 
236  return outOp.GetResult();
237  }
238 
251  V Get(const K& key)
252  {
253  IgniteError err;
254 
255  V res = Get(key, err);
256 
258 
259  return res;
260  }
261 
275  V Get(const K& key, IgniteError& err)
276  {
277  impl::In1Operation<K> inOp(&key);
278  impl::Out1Operation<V> outOp;
279 
280  impl.Get()->Get(inOp, outOp, &err);
281 
282  return outOp.GetResult();
283  }
284 
297  std::map<K, V> GetAll(const std::set<K>& keys)
298  {
299  IgniteError err;
300 
301  std::map<K, V> res = GetAll(keys, err);
302 
304 
305  return res;
306  }
307 
321  std::map<K, V> GetAll(const std::set<K>& keys, IgniteError& err)
322  {
323  impl::InSetOperation<K> inOp(&keys);
324  impl::OutMapOperation<K, V> outOp;
325 
326  impl.Get()->GetAll(inOp, outOp, &err);
327 
328  return outOp.GetResult();
329  }
330 
341  void Put(const K& key, const V& val)
342  {
343  IgniteError err;
344 
345  Put(key, val, err);
346 
348  }
349 
361  void Put(const K& key, const V& val, IgniteError& err)
362  {
363  impl::In2Operation<K, V> op(&key, &val);
364 
365  impl.Get()->Put(op, &err);
366  }
367 
377  void PutAll(const std::map<K, V>& vals)
378  {
379  IgniteError err;
380 
381  PutAll(vals, err);
382 
384  }
385 
396  void PutAll(const std::map<K, V>& vals, IgniteError& err)
397  {
398  impl::InMapOperation<K, V> op(&vals);
399 
400  impl.Get()->PutAll(op, &err);
401  }
402 
414  V GetAndPut(const K& key, const V& val)
415  {
416  IgniteError err;
417 
418  V res = GetAndPut(key, val, err);
419 
421 
422  return res;
423  }
424 
437  V GetAndPut(const K& key, const V& val, IgniteError& err)
438  {
439  impl::In2Operation<K, V> inOp(&key, &val);
440  impl::Out1Operation<V> outOp;
441 
442  impl.Get()->GetAndPut(inOp, outOp, &err);
443 
444  return outOp.GetResult();
445  }
446 
458  V GetAndReplace(const K& key, const V& val)
459  {
460  IgniteError err;
461 
462  V res = GetAndReplace(key, val, err);
463 
465 
466  return res;
467  }
468 
481  V GetAndReplace(const K& key, const V& val, IgniteError& err)
482  {
483  impl::In2Operation<K, V> inOp(&key, &val);
484  impl::Out1Operation<V> outOp;
485 
486  impl.Get()->GetAndReplace(inOp, outOp, &err);
487 
488  return outOp.GetResult();
489  }
490 
499  V GetAndRemove(const K& key)
500  {
501  IgniteError err;
502 
503  V res = GetAndRemove(key, err);
504 
506 
507  return res;
508  }
509 
519  V GetAndRemove(const K& key, IgniteError& err)
520  {
521  impl::In1Operation<K> inOp(&key);
522  impl::Out1Operation<V> outOp;
523 
524  impl.Get()->GetAndRemove(inOp, outOp, &err);
525 
526  return outOp.GetResult();
527  }
528 
539  bool PutIfAbsent(const K& key, const V& val)
540  {
541  IgniteError err;
542 
543  bool res = PutIfAbsent(key, val, err);
544 
546 
547  return res;
548  }
549 
561  bool PutIfAbsent(const K& key, const V& val, IgniteError& err)
562  {
563  impl::In2Operation<K, V> op(&key, &val);
564 
565  return impl.Get()->PutIfAbsent(op, &err);
566  }
567 
586  V GetAndPutIfAbsent(const K& key, const V& val)
587  {
588  IgniteError err;
589 
590  V res = GetAndPutIfAbsent(key, val, err);
591 
593 
594  return res;
595  }
596 
616  V GetAndPutIfAbsent(const K& key, const V& val, IgniteError& err)
617  {
618  impl::In2Operation<K, V> inOp(&key, &val);
619  impl::Out1Operation<V> outOp;
620 
621  impl.Get()->GetAndPutIfAbsent(inOp, outOp, &err);
622 
623  return outOp.GetResult();
624  }
625 
641  bool Replace(const K& key, const V& val)
642  {
643  IgniteError err;
644 
645  bool res = Replace(key, val, err);
646 
648 
649  return res;
650  }
651 
668  bool Replace(const K& key, const V& val, IgniteError& err)
669  {
670  impl::In2Operation<K, V> op(&key, &val);
671 
672  return impl.Get()->Replace(op, &err);
673  }
674 
687  bool Replace(const K& key, const V& oldVal, const V& newVal)
688  {
689  IgniteError err;
690 
691  bool res = Replace(key, oldVal, newVal, err);
692 
694 
695  return res;
696  }
697 
711  bool Replace(const K& key, const V& oldVal, const V& newVal, IgniteError& err)
712  {
713  impl::In3Operation<K, V, V> op(&key, &oldVal, &newVal);
714 
715  return impl.Get()->ReplaceIfEqual(op, &err);
716  }
717 
728  void LocalEvict(const std::set<K>& keys)
729  {
730  IgniteError err;
731 
732  LocalEvict(keys, err);
733 
735  }
736 
748  void LocalEvict(const std::set<K>& keys, IgniteError& err)
749  {
750  impl::InSetOperation<K> op(&keys);
751 
752  impl.Get()->LocalEvict(op, &err);
753  }
754 
760  void Clear()
761  {
762  IgniteError err;
763 
764  Clear(err);
765 
767  }
768 
776  void Clear(IgniteError& err)
777  {
778  impl.Get()->Clear(&err);
779  }
780 
789  void Clear(const K& key)
790  {
791  IgniteError err;
792 
793  Clear(key, err);
794 
796  }
797 
807  void Clear(const K& key, IgniteError& err)
808  {
809  impl::In1Operation<K> op(&key);
810 
811  impl.Get()->Clear(op, &err);
812  }
813 
822  void ClearAll(const std::set<K>& keys)
823  {
824  IgniteError err;
825 
826  ClearAll(keys, err);
827 
829  }
830 
840  void ClearAll(const std::set<K>& keys, IgniteError& err)
841  {
842  impl::InSetOperation<K> op(&keys);
843 
844  impl.Get()->ClearAll(op, &err);
845  }
846 
858  void LocalClear(const K& key)
859  {
860  IgniteError err;
861 
862  LocalClear(key, err);
863 
865  }
866 
879  void LocalClear(const K& key, IgniteError& err)
880  {
881  impl::In1Operation<K> op(&key);
882 
883  impl.Get()->LocalClear(op, &err);
884  }
885 
897  void LocalClearAll(const std::set<K>& keys)
898  {
899  IgniteError err;
900 
901  LocalClearAll(keys, err);
902 
904  }
905 
918  void LocalClearAll(const std::set<K>& keys, IgniteError& err)
919  {
920  impl::InSetOperation<K> op(&keys);
921 
922  impl.Get()->LocalClearAll(op, &err);
923  }
924 
940  bool Remove(const K& key)
941  {
942  IgniteError err;
943 
944  bool res = Remove(key, err);
945 
947 
948  return res;
949  }
950 
967  bool Remove(const K& key, IgniteError& err)
968  {
969  impl::In1Operation<K> op(&key);
970 
971  return impl.Get()->Remove(op, &err);
972  }
973 
985  bool Remove(const K& key, const V& val)
986  {
987  IgniteError err;
988 
989  bool res = Remove(key, val, err);
990 
992 
993  return res;
994  }
995 
1008  bool Remove(const K& key, const V& val, IgniteError& err)
1009  {
1010  impl::In2Operation<K, V> op(&key, &val);
1011 
1012  return impl.Get()->RemoveIfEqual(op, &err);
1013  }
1014 
1024  void RemoveAll(const std::set<K>& keys)
1025  {
1026  IgniteError err;
1027 
1028  RemoveAll(keys, err);
1029 
1031  }
1032 
1043  void RemoveAll(const std::set<K>& keys, IgniteError& err)
1044  {
1045  impl::InSetOperation<K> op(&keys);
1046 
1047  impl.Get()->RemoveAll(op, &err);
1048  }
1049 
1059  void RemoveAll()
1060  {
1061  IgniteError err;
1062 
1063  RemoveAll(err);
1064 
1066  }
1067 
1078  {
1079  return impl.Get()->RemoveAll(&err);
1080  }
1081 
1089  int32_t LocalSize()
1090  {
1091  return LocalSize(IGNITE_PEEK_MODE_ALL);
1092  }
1093 
1102  int32_t LocalSize(IgniteError& err)
1103  {
1104  return LocalSize(IGNITE_PEEK_MODE_ALL, err);
1105  }
1106 
1115  int32_t LocalSize(int32_t peekModes)
1116  {
1117  IgniteError err;
1118 
1119  int32_t res = LocalSize(peekModes, err);
1120 
1122 
1123  return res;
1124  }
1125 
1135  int32_t LocalSize(int32_t peekModes, IgniteError& err)
1136  {
1137  return impl.Get()->LocalSize(peekModes, &err);
1138  }
1139 
1148  int32_t Size()
1149  {
1151  }
1152 
1162  int32_t Size(IgniteError& err)
1163  {
1164  return Size(ignite::cache::IGNITE_PEEK_MODE_ALL, err);
1165  }
1166 
1176  int32_t Size(int32_t peekModes)
1177  {
1178  IgniteError err;
1179 
1180  int32_t res = Size(peekModes, err);
1181 
1183 
1184  return res;
1185  }
1186 
1197  int32_t Size(int32_t peekModes, IgniteError& err)
1198  {
1199  return impl.Get()->Size(peekModes, &err);
1200  }
1201 
1211  {
1212  IgniteError err;
1213 
1214  query::QueryCursor<K, V> res = Query(qry, err);
1215 
1217 
1218  return res;
1219  }
1220 
1231  {
1232  impl::cache::query::QueryCursorImpl* cursorImpl = impl.Get()->QuerySql(qry, &err);
1233 
1234  return query::QueryCursor<K, V>(cursorImpl);
1235  }
1236 
1246  {
1247  IgniteError err;
1248 
1249  query::QueryCursor<K, V> res = Query(qry, err);
1250 
1252 
1253  return res;
1254  }
1255 
1266  {
1267  impl::cache::query::QueryCursorImpl* cursorImpl = impl.Get()->QueryText(qry, &err);
1268 
1269  return query::QueryCursor<K, V>(cursorImpl);
1270  }
1271 
1281  {
1282  IgniteError err;
1283 
1284  query::QueryCursor<K, V> res = Query(qry, err);
1285 
1287 
1288  return res;
1289  }
1290 
1301  {
1302  impl::cache::query::QueryCursorImpl* cursorImpl = impl.Get()->QueryScan(qry, &err);
1303 
1304  return query::QueryCursor<K, V>(cursorImpl);
1305  }
1306 
1316  {
1317  IgniteError err;
1318 
1319  query::QueryFieldsCursor res = Query(qry, err);
1320 
1322 
1323  return res;
1324  }
1325 
1336  {
1337  impl::cache::query::QueryCursorImpl* cursorImpl = impl.Get()->QuerySqlFields(qry, &err);
1338 
1339  return query::QueryFieldsCursor(cursorImpl);
1340  }
1341 
1353  bool IsValid() const
1354  {
1355  return impl.IsValid();
1356  }
1357 
1358  private:
1360  ignite::common::concurrent::SharedPointer<impl::cache::CacheImpl> impl;
1361  };
1362  }
1363 }
1364 
1365 #endif //_IGNITE_CACHE_CACHE
const char * GetName() const
Get name of this cache (null for default cache).
Definition: cache.h:83
query::QueryCursor< K, V > Query(const query::TextQuery &qry)
Perform text query.
Definition: cache.h:1245
void ClearAll(const std::set< K > &keys)
Clear entries from the cache and swap storage, without notifying listeners or CacheWriters.
Definition: cache.h:822
Text query.
Definition: query_text.h:40
void Clear()
Clear cache.
Definition: cache.h:760
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:437
int32_t LocalSize(int32_t peekModes)
Gets the number of all entries cached on this node.
Definition: cache.h:1115
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:918
Declares ignite::cache::query::QueryCursor class template.
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:985
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:789
Main entry point for all Data Grid APIs.
Definition: cache.h:60
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:1008
int32_t Size()
Gets the number of all entries cached across all nodes.
Definition: cache.h:1148
bool ContainsKeys(const std::set< K > &keys)
Check if cache contains mapping for these keys.
Definition: cache.h:164
query::QueryCursor< K, V > Query(const query::SqlQuery &qry)
Perform SQL query.
Definition: cache.h:1210
void Clear(const K &key, IgniteError &err)
Clear entry from the cache and swap storage, without notifying listeners or CacheWriters.
Definition: cache.h:807
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:616
Cache(impl::cache::CacheImpl *impl)
Constructor.
Definition: cache.h:70
bool Remove(const K &key)
Removes given key mapping from cache.
Definition: cache.h:940
bool IsEmpty(IgniteError &err)
Checks whether this cache contains no key-value mappings.
Definition: cache.h:116
void Clear(IgniteError &err)
Clear cache.
Definition: cache.h:776
bool ContainsKeys(const std::set< K > &keys, IgniteError &err)
Check if cache contains mapping for these keys.
Definition: cache.h:184
V Get(const K &key, IgniteError &err)
Retrieves value mapped to the specified key from cache.
Definition: cache.h:275
void RemoveAll()
Removes all mappings from cache.
Definition: cache.h:1059
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:1280
query::QueryCursor< K, V > Query(const query::SqlQuery &qry, IgniteError &err)
Perform SQL query.
Definition: cache.h:1230
V GetAndRemove(const K &key, IgniteError &err)
Atomically removes the entry for a key only if currently mapped to some value.
Definition: cache.h:519
V LocalPeek(const K &key, int32_t peekModes)
Peeks at cached value using optional set of peek modes.
Definition: cache.h:204
void RemoveAll(const std::set< K > &keys)
Removes given key mappings from cache.
Definition: cache.h:1024
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:711
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:840
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:414
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:129
void LocalClear(const K &key)
Clear entry from the cache and swap storage, without notifying listeners or CacheWriters.
Definition: cache.h:858
int32_t Size(IgniteError &err)
Gets the number of all entries cached across all nodes.
Definition: cache.h:1162
bool IsEmpty()
Checks whether this cache contains no key-value mappings.
Definition: cache.h:96
bool IsValid() const
Check if the instance is valid.
Definition: cache.h:1353
void RemoveAll(const std::set< K > &keys, IgniteError &err)
Removes given key mappings from cache.
Definition: cache.h:1043
void PutAll(const std::map< K, V > &vals)
Stores given key-value pairs in cache.
Definition: cache.h:377
void LocalEvict(const std::set< K > &keys, IgniteError &err)
Attempts to evict all entries associated with keys.
Definition: cache.h:748
V GetAndRemove(const K &key)
Atomically removes the entry for a key only if currently mapped to some value.
Definition: cache.h:499
Peeks into all available cache storages.
Definition: cache_peek_mode.h:38
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:251
void Put(const K &key, const V &val)
Associates the specified value with the specified key in the cache.
Definition: cache.h:341
void LocalEvict(const std::set< K > &keys)
Attempts to evict all entries associated with keys.
Definition: cache.h:728
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:687
int32_t Size(int32_t peekModes, IgniteError &err)
Gets the number of all entries cached across all nodes.
Definition: cache.h:1197
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:539
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:668
int32_t Size(int32_t peekModes)
Gets the number of all entries cached across all nodes.
Definition: cache.h:1176
std::map< K, V > GetAll(const std::set< K > &keys)
Retrieves values mapped to the specified keys from cache.
Definition: cache.h:297
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:481
static void ThrowIfNeeded(IgniteError &err)
Throw an error if code is not IGNITE_SUCCESS.
Definition: ignite_error.cpp:27
bool ContainsKey(const K &key, IgniteError &err)
Check if cache contains mapping for this key.
Definition: cache.h:149
void PutAll(const std::map< K, V > &vals, IgniteError &err)
Stores given key-value pairs in cache.
Definition: cache.h:396
V LocalPeek(const K &key, int32_t peekModes, IgniteError &err)
Peeks at cached value using optional set of peek modes.
Definition: cache.h:229
int32_t LocalSize(IgniteError &err)
Gets the number of all entries cached on this node.
Definition: cache.h:1102
Declares ignite::cache::query::SqlFieldsQuery class.
Ignite error information.
Definition: ignite_error.h:89
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:586
void LocalClearAll(const std::set< K > &keys)
Clear entries from the cache and swap storage, without notifying listeners or CacheWriters.
Definition: cache.h:897
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:561
void Put(const K &key, const V &val, IgniteError &err)
Associates the specified value with the specified key in the cache.
Definition: cache.h:361
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:458
query::QueryCursor< K, V > Query(const query::ScanQuery &qry, IgniteError &err)
Perform scan query.
Definition: cache.h:1300
Apache Ignite API.
Definition: cache.h:43
query::QueryCursor< K, V > Query(const query::TextQuery &qry, IgniteError &err)
Perform text query.
Definition: cache.h:1265
Declares ignite::IgniteError class.
query::QueryFieldsCursor Query(const query::SqlFieldsQuery &qry, IgniteError &err)
Perform sql fields query.
Definition: cache.h:1335
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:641
query::QueryFieldsCursor Query(const query::SqlFieldsQuery &qry)
Perform sql fields query.
Definition: cache.h:1315
Query cursor class template.
Definition: query_cursor.h:54
void RemoveAll(IgniteError &err)
Removes all mappings from cache.
Definition: cache.h:1077
std::map< K, V > GetAll(const std::set< K > &keys, IgniteError &err)
Retrieves values mapped to the specified keys from cache.
Definition: cache.h:321
int32_t LocalSize()
Gets the number of all entries cached on this node.
Definition: cache.h:1089
bool Remove(const K &key, IgniteError &err)
Removes given key mapping from cache.
Definition: cache.h:967
void LocalClear(const K &key, IgniteError &err)
Clear entry from the cache and swap storage, without notifying listeners or CacheWriters.
Definition: cache.h:879
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:1135