template<typename Key, typename Value, typename Hash = std::hash<Key>, typename Equal = std::equal_to<Key>>
class cache::LruCacheWrapper< Key, Value, Hash, Equal >
Wrapper around ExpirableLruCache that binds an update function for convenience.
auto cache_ptr = std::make_shared<cache::ExpirableLruCache<std::string, int>>(1, 1);
static std::atomic<int> counter{0};
return ++counter;
});
const std::string key = "my-key";
EXPECT_EQ(std::nullopt, wrapper.GetOptional(key));
EXPECT_EQ(1, wrapper.Get(key));
EXPECT_EQ(std::make_optional(1), wrapper.GetOptional(key));
wrapper.InvalidateByKey(key);
EXPECT_EQ(2, wrapper.Get(key));
EXPECT_EQ(std::make_optional(2), wrapper.GetOptional(key));
Definition at line 492 of file expirable_lru_cache.hpp.
|
| | LruCacheWrapper (std::shared_ptr< Cache > cache, typename Cache::UpdateValueFunc update_func) |
| | Constructs wrapper with shared cache and update function.
|
| |
| Value | Get (const Key &key, ReadMode read_mode=ReadMode::kUseCache) |
| | Returns cached value or computes it if key is missing in cache.
|
| |
| std::optional< Value > | GetOptional (const Key &key) |
| | Returns cached value or std::nullopt if key is missing in cache.
|
| |
| void | InvalidateByKey (const Key &key) |
| | Erases key from cache.
|
| |
| template<typename Predicate> |
| void | InvalidateByKeyIf (const Key &key, Predicate pred) |
| | Erases key from cache if pred returns true for the current value.
|
| |
| void | UpdateInBackground (const Key &key) |
| | Schedules background update of cached value for the key.
|
| |
| std::shared_ptr< Cache > | GetCache () |
| | Returns raw cache pointer.
|
| |