30 template <
typename K,
typename V,
typename MutexT>
32 std::size_t cacheCapacity,
33 std::chrono::milliseconds syncInterval,
44 template <
typename K,
typename V,
typename MutexT>
46 std::shared_ptr<folly::Executor>
executor,
47 std::size_t cacheCapacity,
48 std::chrono::milliseconds syncInterval,
68 template<
typename K,
typename V,
typename MutexT>
89 template <
typename K,
typename V,
typename MutexT>
99 std::weak_ptr<LRUPersistentCache<K, V, MutexT>> weakSelf =
100 this->shared_from_this();
103 if (
auto sharedSelf =
self.
lock()) {
104 sharedSelf->oneShotSync();
111 template<
typename K,
typename V,
typename MutexT>
120 template<
typename K,
typename V,
typename MutexT>
129 template <
typename K,
typename V,
typename MutexT>
133 if (persistence && !
syncNow(*persistence)) {
137 persistence->setPersistedVersion(
cache_.getVersion());
145 template<
typename K,
typename V,
typename MutexT>
150 int nSyncFailures = 0;
155 !
cache_.hasChangedSince(persistence->getLastPersistedVersion())) {
160 if (persistence && !
syncNow(*persistence)) {
164 persistence->setPersistedVersion(
cache_.getVersion());
177 template<
typename K,
typename V,
typename MutexT>
190 auto serializedCacheAndVersion =
cache_.convertToKeyValuePairs();
191 if (!serializedCacheAndVersion) {
192 LOG(ERROR) <<
"Failed to convert cache for serialization.";
196 auto& kvPairs = std::get<0>(serializedCacheAndVersion.value());
197 auto&
version = std::get<1>(serializedCacheAndVersion.value());
204 template<
typename K,
typename V,
typename MutexT>
205 std::shared_ptr<CachePersistence<K, V>>
211 template<
typename K,
typename V,
typename MutexT>
226 template<
typename K ,
typename V,
typename MutexT>
235 template<
typename K,
typename V,
typename MutexT>
238 auto kvPairs = persistence.load();
242 return cache_.loadData(kvPairs.value());
std::shared_ptr< CachePersistence< K, V > > persistence_
void put(const K &key, const V &val) override
std::condition_variable stopSyncerCV_
uint64_t CacheDataVersion
std::chrono::steady_clock::time_point now()
constexpr detail::Map< Move > move
std::shared_ptr< folly::Executor > executor_
requires E e noexcept(noexcept(s.error(std::move(e))))
std::atomic_flag executorScheduled_
PUSHMI_INLINE_VAR constexpr __adl::get_executor_fn executor
std::chrono::steady_clock::time_point lastExecutorScheduleTime_
void setPersistenceHelper(std::unique_ptr< CachePersistence< K, V >> persistence, bool syncVersion) noexcept
void setPersistence(std::unique_ptr< CachePersistence< K, V >> persistence)
bool persistVersionedData(const folly::dynamic &kvPairs, const CacheDataVersion &version)
LRUInMemoryCache< K, V, MutexT > cache_
auto lock(SynchronizedLocker...lockersIn) -> std::tuple< typename SynchronizedLocker::LockedPtr... >
~LRUPersistentCache() override
const std::chrono::milliseconds syncInterval_
bool syncNow(CachePersistence< K, V > &persistence)
bool setThreadName(std::thread::id tid, StringPiece name)
std::shared_ptr< CachePersistence< K, V > > getPersistence()
LRUPersistentCache(std::size_t cacheCapacity, std::chrono::milliseconds syncInterval=client::persistence::DEFAULT_CACHE_SYNC_INTERVAL, int nSyncRetries=client::persistence::DEFAULT_CACHE_SYNC_RETRIES, std::unique_ptr< CachePersistence< K, V >> persistence=nullptr)
static void * syncThreadMain(void *arg)
std::mutex stopSyncerMutex_
CacheDataVersion load(CachePersistence< K, V > &persistence) noexcept
virtual CacheDataVersion getLastPersistedVersion() const