Apache Ignite C++
cache_client.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_THIN_CACHE_CACHE_CLIENT
24 #define _IGNITE_THIN_CACHE_CACHE_CLIENT
25 
26 #include <ignite/common/concurrent.h>
27 
28 #include <ignite/impl/thin/writable.h>
29 #include <ignite/impl/thin/writable_key.h>
30 #include <ignite/impl/thin/readable.h>
31 
32 #include <ignite/impl/thin/cache/cache_client_proxy.h>
33 
34 namespace ignite
35 {
36  namespace thin
37  {
38  namespace cache
39  {
55  template<typename K, typename V>
57  {
58  friend class impl::thin::cache::CacheClientProxy;
59 
60  public:
62  typedef K KeyType;
63 
65  typedef V ValueType;
66 
72  CacheClient(common::concurrent::SharedPointer<void> impl) :
73  proxy(impl)
74  {
75  // No-op.
76  }
77 
82  {
83  // No-op.
84  }
85 
90  {
91  // No-op.
92  }
93 
100  void Put(const KeyType& key, const ValueType& value)
101  {
102  impl::thin::WritableKeyImpl<KeyType> wrKey(key);
103  impl::thin::WritableImpl<ValueType> wrValue(value);
104 
105  proxy.Put(wrKey, wrValue);
106  }
107 
115  template<typename InIter>
116  void PutAll(InIter begin, InIter end)
117  {
118  impl::thin::WritableMapImpl<K, V, InIter> wrSeq(begin, end);
119 
120  proxy.PutAll(wrSeq);
121  }
122 
129  template<typename Map>
130  void PutAll(const Map& vals)
131  {
132  PutAll(vals.begin(), vals.end());
133  }
134 
141  void Get(const KeyType& key, ValueType& value)
142  {
143  impl::thin::WritableKeyImpl<KeyType> wrKey(key);
144  impl::thin::ReadableImpl<ValueType> rdValue(value);
145 
146  proxy.Get(wrKey, rdValue);
147  }
148 
155  ValueType Get(const KeyType& key)
156  {
157  ValueType value;
158 
159  Get(key, value);
160 
161  return value;
162  }
163 
174  template<typename InIter, typename OutIter>
175  void GetAll(InIter begin, InIter end, OutIter dst)
176  {
177  impl::thin::WritableSetImpl<K, InIter> wrSeq(begin, end);
178  impl::thin::ReadableMapImpl<K, V, OutIter> rdSeq(dst);
179 
180  proxy.GetAll(wrSeq, rdSeq);
181  }
182 
192  template<typename Set, typename Map>
193  void GetAll(const Set& keys, Map& res)
194  {
195  return GetAll(keys.begin(), keys.end(), std::inserter(res, res.end()));
196  }
197 
210  bool Replace(const K& key, const V& value)
211  {
212  impl::thin::WritableKeyImpl<KeyType> wrKey(key);
213  impl::thin::WritableImpl<ValueType> wrValue(value);
214 
215  return proxy.Replace(wrKey, wrValue);
216  }
217 
224  bool ContainsKey(const KeyType& key)
225  {
226  impl::thin::WritableKeyImpl<KeyType> wrKey(key);
227 
228  return proxy.ContainsKey(wrKey);
229  }
230 
237  template<typename Set>
238  bool ContainsKeys(const Set& keys)
239  {
240  return ContainsKeys(keys.begin(), keys.end());
241  }
242 
250  template<typename InIter>
251  bool ContainsKeys(InIter begin, InIter end)
252  {
253  impl::thin::WritableSetImpl<K, InIter> wrSeq(begin, end);
254 
255  return proxy.ContainsKeys(wrSeq);
256  }
257 
267  int64_t GetSize(int32_t peekModes)
268  {
269  return proxy.GetSize(peekModes);
270  }
271 
284  bool Remove(const KeyType& key)
285  {
286  impl::thin::WritableKeyImpl<KeyType> wrKey(key);
287 
288  return proxy.Remove(wrKey);
289  }
290 
297  template<typename Set>
298  void RemoveAll(const Set& keys)
299  {
300  RemoveAll(keys.begin(), keys.end());
301  }
302 
310  template<typename InIter>
311  void RemoveAll(InIter begin, InIter end)
312  {
313  impl::thin::WritableSetImpl<K, InIter> wrSeq(begin, end);
314 
315  proxy.RemoveAll(wrSeq);
316  }
317 
323  void RemoveAll()
324  {
325  proxy.RemoveAll();
326  }
327 
334  void Clear(const KeyType& key)
335  {
336  impl::thin::WritableKeyImpl<KeyType> wrKey(key);
337 
338  proxy.Clear(wrKey);
339  }
340 
344  void Clear()
345  {
346  proxy.Clear();
347  }
348 
355  template<typename Set>
356  void ClearAll(const Set& keys)
357  {
358  ClearAll(keys.begin(), keys.end());
359  }
360 
368  template<typename InIter>
369  void ClearAll(InIter begin, InIter end)
370  {
371  impl::thin::WritableSetImpl<K, InIter> wrSeq(begin, end);
372 
373  proxy.ClearAll(wrSeq);
374  }
375 
386  {
387  proxy.RefreshAffinityMapping();
388  }
389 
390  private:
392  impl::thin::cache::CacheClientProxy proxy;
393  };
394  }
395  }
396 }
397 
398 #endif // _IGNITE_THIN_CACHE_CACHE_CLIENT
V ValueType
Value type.
Definition: cache_client.h:65
void GetAll(InIter begin, InIter end, OutIter dst)
Retrieves values mapped to the specified keys from cache.
Definition: cache_client.h:175
void RemoveAll()
Removes all mappings from cache.
Definition: cache_client.h:323
CacheClient(common::concurrent::SharedPointer< void > impl)
Constructor.
Definition: cache_client.h:72
int64_t GetSize(int32_t peekModes)
Gets the number of all entries cached across all nodes.
Definition: cache_client.h:267
void RemoveAll(InIter begin, InIter end)
Removes given key mappings from cache.
Definition: cache_client.h:311
K KeyType
Key type.
Definition: cache_client.h:62
bool ContainsKeys(InIter begin, InIter end)
Check if cache contains mapping for these keys.
Definition: cache_client.h:251
~CacheClient()
Destructor.
Definition: cache_client.h:89
bool Replace(const K &key, const V &value)
Stores given key-value pair in cache only if there is a previous mapping for it.
Definition: cache_client.h:210
ValueType Get(const KeyType &key)
Get value from cache.
Definition: cache_client.h:155
void PutAll(const Map &vals)
Stores given key-value pairs in cache.
Definition: cache_client.h:130
void PutAll(InIter begin, InIter end)
Stores given key-value pairs in cache.
Definition: cache_client.h:116
CacheClient()
Default constructor.
Definition: cache_client.h:81
bool ContainsKeys(const Set &keys)
Check if cache contains mapping for these keys.
Definition: cache_client.h:238
void Clear(const KeyType &key)
Clear entry from the cache and swap storage, without notifying listeners or CacheWriters.
Definition: cache_client.h:334
void Put(const KeyType &key, const ValueType &value)
Associate the specified value with the specified key in the cache.
Definition: cache_client.h:100
void RefreshAffinityMapping()
Refresh affinity mapping.
Definition: cache_client.h:385
void GetAll(const Set &keys, Map &res)
Retrieves values mapped to the specified keys from cache.
Definition: cache_client.h:193
Cache client class template.
Definition: cache_client.h:56
bool Remove(const KeyType &key)
Removes given key mapping from cache.
Definition: cache_client.h:284
void RemoveAll(const Set &keys)
Removes given key mappings from cache.
Definition: cache_client.h:298
void ClearAll(InIter begin, InIter end)
Clear entries from the cache and swap storage, without notifying listeners or CacheWriters.
Definition: cache_client.h:369
Apache Ignite API.
Definition: cache.h:48
bool ContainsKey(const KeyType &key)
Check if the cache contains a value for the specified key.
Definition: cache_client.h:224
void ClearAll(const Set &keys)
Clear entries from the cache and swap storage, without notifying listeners or CacheWriters.
Definition: cache_client.h:356
void Clear()
Clear cache.
Definition: cache_client.h:344
void Get(const KeyType &key, ValueType &value)
Get value from the cache.
Definition: cache_client.h:141