swift
Public Member Functions | List of all members
swift::misc::CDataCacheRevision Class Reference

Encapsulates metastate about how the version of the cache in memory compares to the one on disk. More...

Public Member Functions

 CDataCacheRevision (const QString &basename)
 Construct the single instance of the revision metastate.
 
 ~CDataCacheRevision ()
 Destructor.
 
LockGuard beginUpdate (const QMap< QString, qint64 > &timestamps, bool updateUuid=true, bool pinsOnly=false)
 Get the state of the disk cache, and prepare to update any values which are out of date. Return value can be converted to bool, false means update is not started (error, or already up-to-date). More...
 
void writeNewRevision (const QMap< QString, qint64 > &timestamps, const QSet< QString > &excludeKeys={})
 During update, writes a new revision file with new timestamps.
 
void regenerate (const CValueCachePacket &keys)
 Write a new revision file with keys deduced from the available JSON files.
 
void finishUpdate (bool keepPromises=false)
 Release the revision file lock and mark everything up-to-date (called by LockGuard destructor). More...
 
bool isFound () const
 Existing revision file was found.
 
bool isPendingRead () const
 True if beginUpdate found some values with timestamps newer than in memory.
 
void notifyPendingWrite ()
 Call before beginUpdate if there is a write pending, so update will start even if there is nothing to read.
 
QSet< QString > keysWithNewerTimestamps () const
 During update, returns keys which have on-disk timestamps newer than in-memory. Guaranteed not empty.
 
const QMap< QString, qint64 > & newerTimestamps () const
 During update, returns timestamps which have on-disk timestamps newer than in-memory. Guaranteed not empty.
 
bool isNewerValueAvailable (const QString &key, qint64 timestamp)
 During update, returns true if the on-disk timestamp of this key is newer than in-memory.
 
std::future< void > promiseLoadedValue (const QString &key, qint64 currentTimestamp)
 Return a future which will be made ready when the value is loaded. Future is invalid if value is not loading.
 
std::vector< std::promise< void > > loadedValuePromises ()
 Returns (by move) the container of promises to load values.
 
void breakPromises ()
 Abandon all promises.
 
QString timestampsAsString () const
 Keys with timestamps.
 
void setTimeToLive (const QString &key, int ttl)
 Set TTL value that will be written to the revision file.
 
void overrideTimestamp (const QString &key, qint64 timestamp)
 Causes the new timestamp to be written to the revision file.
 
qint64 getTimestampOnDisk (const QString &key)
 Read the revision file to get a timestamp.
 
void pinValue (const QString &key)
 Set the flag which will cause the value to be pre-loaded.
 
void deferValue (const QString &key)
 Set the flag which will cause the value to be deferred-loaded.
 
void admitValue (const QString &key)
 Set the flag which will cause a deferred-load value to be loaded.
 
void sessionValue (const QString &key)
 Set the flag which will cause a value to be reset when starting a new session.
 
 CDataCacheRevision (const CDataCacheRevision &)=delete
 Non-copyable.
 
CDataCacheRevisionoperator= (const CDataCacheRevision &)=delete
 Non-copyable.
 

Detailed Description

Encapsulates metastate about how the version of the cache in memory compares to the one on disk.

Remarks
This function is thread safe.

Definition at line 79 of file datacache.h.

Member Function Documentation

◆ beginUpdate()

LockGuard swift::misc::CDataCacheRevision::beginUpdate ( const QMap< QString, qint64 > &  timestamps,
bool  updateUuid = true,
bool  pinsOnly = false 
)

Get the state of the disk cache, and prepare to update any values which are out of date. Return value can be converted to bool, false means update is not started (error, or already up-to-date).

Parameters
timestampsCurrent in-memory timestamps, to be compared with the on-disk ones.
updateUuidWhether to prepare for an actual update, or just interrograte whether one is needed.
pinsOnlyOnly load pinned values.

◆ finishUpdate()

void swift::misc::CDataCacheRevision::finishUpdate ( bool  keepPromises = false)

Release the revision file lock and mark everything up-to-date (called by LockGuard destructor).

Parameters
keepPromisesDon't break pending promises.

The documentation for this class was generated from the following file: