in wangle/client/persistence/LRUPersistentCache-inl.h [157:189]
void LRUPersistentCache<K, V, MutexT>::sync() {
// load the cache. be silent if load fails, we just drop the cache
// and start from scratch.
setPersistenceHelper(true);
// keep running as long the destructor signals to stop or
// there are pending updates that are not synced yet
std::unique_lock<std::mutex> stopSyncerLock(stopSyncerMutex_);
int nSyncFailures = 0;
while (true) {
auto persistence = getPersistence();
if (stopSyncer_) {
if (!persistence ||
!cache_.hasChangedSince(persistence->getLastPersistedVersion())) {
break;
}
}
if (persistence && !syncNow(*persistence)) {
// track failures and give up if we tried too many times
++nSyncFailures;
if (nSyncFailures == nSyncRetries_) {
persistence->setPersistedVersion(cache_.getVersion());
nSyncFailures = 0;
}
} else {
nSyncFailures = 0;
}
if (!stopSyncer_) {
stopSyncerCV_.wait_for(stopSyncerLock, syncInterval_);
}
}
}