/
configcache.h
43 lines (34 loc) · 1.07 KB
/
configcache.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#pragma once
#include <string>
namespace configcat {
// A cache API used to make custom cache implementations.
class ConfigCache {
public:
/**
* Child classes has to implement this method, the [ConfigCatClient] is
* using it to get the actual value from the cache.
*
* [key] is the key of the cache entry.
*/
virtual const std::string& read(const std::string& key) = 0;
/**
* Child classes has to implement this method, the [ConfigCatClient] is
* using it to set the actual cached value.
*
* [key] is the key of the cache entry.
* [value] is the new value to cache.
*/
virtual void write(const std::string& key, const std::string& value) = 0;
virtual ~ConfigCache() = default;
};
class NullConfigCache : public ConfigCache {
public:
inline static const std::string emptyString = "";
const std::string& read(const std::string& key) override {
return emptyString;
}
void write(const std::string& key, const std::string& value) override {
// do nothing
}
};
} // namespace configcat