C++ Client-Side SDK
LaunchDarkly SDK
Loading...
Searching...
No Matches
flag_persistence.hpp
1#pragma once
2
3#include <chrono>
4#include <functional>
5#include <mutex>
6
7#include "../data_sources/data_source_update_sink.hpp"
8#include "context_index.hpp"
9#include "flag_store.hpp"
10
11#include <launchdarkly/context.hpp>
12#include <launchdarkly/logging/logger.hpp>
13#include <launchdarkly/persistence/persistence.hpp>
14
15namespace launchdarkly::client_side::flag_manager {
16
17std::string PersistenceEncodeKey(std::string const& input);
18
20 public:
21 using TimeStampsource =
22 std::function<std::chrono::time_point<std::chrono::system_clock>()>;
23
25 std::string const& sdk_key,
27 FlagStore& flag_store,
28 std::shared_ptr<IPersistence> persistence,
29 Logger& logger,
30 std::size_t max_cached_contexts,
31 TimeStampsource time_stamper = []() {
32 return std::chrono::system_clock::now();
33 });
34
35 void Init(Context const& context,
36 std::unordered_map<std::string, ItemDescriptor> data) override;
37
38 void Upsert(Context const& context,
39 std::string key,
40 ItemDescriptor item) override;
41
42 void LoadCached(Context const& context);
43
44 private:
45 inline static std::string global_namespace_ = "LaunchDarkly";
46 inline static std::string index_key_ = "ContextIndex";
47
48 Logger& logger_;
49 std::size_t max_cached_contexts_;
50
52 std::shared_ptr<IPersistence> persistence_;
53 mutable std::recursive_mutex persistence_mutex_;
54 FlagStore& flag_store_;
55
56 std::string environment_namespace_;
57 TimeStampsource time_stamper_;
58
59 ContextIndex GetIndex();
60 void StoreCache(std::string const& context_id);
61};
62
63} // namespace launchdarkly::client_side::flag_manager
Definition context.hpp:29
Definition data_source_update_sink.hpp:21