ScaleOut C++ Native Client API  5.1
 All Classes Functions Variables Typedefs Enumerations Enumerator Friends Pages
typed_named_cache.h
1 /*
2  Copyright (c) 2013 by ScaleOut Software, Inc.
3 
4  Licensed under the Apache License, Version 2.0 (the "License");
5  you may not use this file except in compliance with the License.
6  You may obtain a copy of the License at
7 
8  http://www.apache.org/licenses/LICENSE-2.0
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15 */
16 
17 #pragma once
18 
19 #include <vector>
20 
21 #include "boost/version.hpp"
22 #include "boost/shared_ptr.hpp"
23 #include "boost/make_shared.hpp"
24 #include "boost/thread.hpp"
25 #include "soss_client/named_cache.h"
26 #include "soss_client/get_options.h"
27 #include "soss_client/put_options.h"
28 #include "soss_client/get_result.h"
29 #include "soss_client/internal/put_helper.h"
30 
31 namespace sosscli {
32 
36 template <typename T>
38 {
39 public:
40 
42  virtual ~TypedNamedCache() {}
43 
44  /* Cache operations */
45 
58  PutResult put(SossKey key, const boost::shared_ptr<T> obj_ptr, const ObjectPolicy &obj_policy = ObjectPolicy::CACHE_DEFAULTS, const PutOptions &options = PutOptions::CACHE_DEFAULTS);
59 
70  PutResult insert(SossKey key, const boost::shared_ptr<T> obj_ptr, const ObjectPolicy &obj_policy = ObjectPolicy::CACHE_DEFAULTS, const PutOptions &options = PutOptions::CACHE_DEFAULTS);
71 
84  PutResult insert_and_lock(SossKey key, const boost::shared_ptr<T> obj_ptr, const ObjectPolicy &obj_policy = ObjectPolicy::CACHE_DEFAULTS, const PutOptions &options = PutOptions::CACHE_DEFAULTS);
85 
97  PutResult update(SossKey key, const boost::shared_ptr<T> obj_ptr, const PutOptions &options = PutOptions::CACHE_DEFAULTS);
98 
111  PutResult update_locked_and_retain(SossKey key, const boost::shared_ptr<T> obj_ptr, LockTicket lock_ticket, const PutOptions &options = PutOptions::CACHE_DEFAULTS);
112 
123  PutResult update_locked_and_release(SossKey key, const boost::shared_ptr<T> obj_ptr, LockTicket lock_ticket, const PutOptions &options = PutOptions::CACHE_DEFAULTS);
124 
164  PutResult update_optimistic(SossKey key, const boost::shared_ptr<T> obj_ptr, int32_t version, const PutOptions &options = PutOptions::CACHE_DEFAULTS);
165 
176 
199 
213 
231  void set_missed_object_callback(boost::function<boost::shared_ptr<T>(const SossKey &key)> callback) { missed_object_callback_ = callback; }
232 
234  boost::function<boost::shared_ptr<T>(const SossKey &key)> missed_object_callback() const {return missed_object_callback_;}
235 
236 protected:
237  /* Extension points for subclasses */
238 
244  virtual boost::shared_ptr<T> deserialize(const std::vector<uint8_t> &bytes) = 0;
245 
252  virtual void serialize(const T& object, std::vector<uint8_t> &bytes_out, std::vector<uint8_t> &prop_spec_out) = 0;
253 
256  GetResult<T> get(SossKey& key, uint32_t flags, LockTicket lock_ticket, const GetOptions<T> &options);
257 
260  PutResult put(SossKey &key, const boost::shared_ptr<T> obj_ptr, const ObjectPolicy &obj_policy, uint32_t put_flags, const PutOptions &options, LockTicket lock_ticket, int32_t version);
261 
262 private:
263 
264  // optional callback that can be used to create a missing object.
265  boost::function<boost::shared_ptr<T>(const SossKey &key)> missed_object_callback_;
266 
267 };
268 
269 } // namespace
270 
271 #include "soss_client/internal/typed_named_cache-impl.h"