template<typename Key, typename Value, typename Hash = std::hash<Key>, typename Equal = std::equal_to<Key>>
class cache::ExpirableLruCache< Key, Value, Hash, Equal >
Class for expirable LRU cache. Use cache::LruMap for not expirable LRU Cache.
Example usage:
using Key = std::string;
using Value = int;
cache .SetMaxLifetime(std::chrono::seconds(3));
utils::datetime::MockNowSet(std::chrono::system_clock::now());
Key key1 = "first-key" ;
Key key2 = "second-key" ;
EXPECT_EQ(41,
cache .GetOptionalNoUpdate(key1));
EXPECT_EQ(std::nullopt,
cache .GetOptionalNoUpdate(key1));
EXPECT_EQ(42,
cache .GetOptionalNoUpdate(key2));
utils::datetime::MockSleep(std::chrono::seconds(2));
EXPECT_EQ(42,
cache .GetOptionalNoUpdate(key2));
utils::datetime::MockSleep(std::chrono::seconds(2));
EXPECT_EQ(std::nullopt,
cache .GetOptionalNoUpdate(key2));
Definition at line 61 of file expirable_lru_cache.hpp .
template<typename Key , typename Value , typename Hash , typename Equal >
GetOptional, but without expiry checks and value updates.
Used during fallback in FallbackELruCache.
Definition at line 253 of file expirable_lru_cache.hpp .
template<typename Key , typename Value , typename Hash , typename Equal >
std::optional< Value > cache::ExpirableLruCache < Key, Value, Hash, Equal >::GetOptionalUnexpirableWithUpdate
(
const Key &
key ,
const UpdateValueFunc &
update_func
)
GetOptional, but without expiry check.
Used during fallback in FallbackELruCache.
Definition at line 268 of file expirable_lru_cache.hpp .
template<typename Key , typename Value , typename Hash , typename Equal >
Sets background update mode. If "background_update" mode is kDisabled, expiring values are not updated in background (asynchronously) or are updated if "background_update" is kEnabled.
Definition at line 197 of file expirable_lru_cache.hpp .