Remoto - VFS: VFS_datastore_cache_entry Class Reference
Remoto - VFS

A pure virtual class which must be subclassed for data storage. More...

#include <VFS_datastore.h>

Inheritance diagram for VFS_datastore_cache_entry:
VFS_HD_cache_entry VFS_mongo_cache_entry

Public Slots

virtual void timerEvent (QTimerEvent *e)
 Either a flush or expire has happened. More...
 

Signals

void expired (VFS_datastore_cache_entry *)
 Signal emitted when a cache entry has expired and is no longer in use. More...
 
void touched ()
 Signal emitted when a cache entry has made a change and should climb the cache queue. More...
 

Public Member Functions

 VFS_datastore_cache_entry (bool debug, int flushInterval, int expireInterval, bool raw=false)
 Construct the cache entry. More...
 
virtual ~VFS_datastore_cache_entry ()
 Destroy the cache entry. More...
 
virtual QJsonDocument getData ()
 Return the data from an entry. More...
 
virtual QByteArray getRawData ()
 Return the data from an entry. More...
 
virtual void setData (QByteArray data)
 Write raw data to the entry. More...
 
virtual void setData (QJsonObject json)
 Write data to the entry. More...
 
quint64 size ()
 
virtual bool valid (QString &reason)
 

Public Attributes

QString _key
 The cache entry key. More...
 

Protected Member Functions

virtual void flush ()=0
 A pure virtual function that must be overridden in subclasses. This is the function that actually commits data to a storage medium. More...
 
virtual void touch ()
 Reset the expiration timer. More...
 

Protected Attributes

QJsonDocument _data
 The actual cache data. More...
 
bool _debug
 Debug flag, for verbose output. More...
 
bool _dirty
 Changes have occurred but they are not commited to storage yet. More...
 
int _expireID
 Timer ID for expire events. More...
 
int _expireInterval
 Expire interval, in milliseconds. More...
 
QBasicTimer _expireTimer
 The expiration timer. More...
 
int _flushID
 Timer ID for flush events. More...
 
int _flushInterval
 Flush interval, in milliseconds. More...
 
bool _raw
 A convenience flag used in subclasses. Not used by this class. More...
 
QByteArray _rawData
 Raw binary data. Used if _raw=true. More...
 
QString _reason
 The reason this may be invalid. Set by a subclass. More...
 
quint64 _size
 The size of the data. Always initialized to zero. Must be set in a subclass. More...
 
bool _valid
 Defaults to false. A subclass will determine if _valid is true, like for instance if an underlying file doesn't exist. More...
 

Detailed Description

A pure virtual class which must be subclassed for data storage.

This class will provide basic functionality for caching data before flushing to a storage medium. It is designed to act as an entry in a VFS_datastore_cache.

Cache entries will flush at some interval if _dirty, regardless of expire status. touch() will restart the expire timer, pushing expiration into the future.

Definition at line 12 of file VFS_datastore.h.

Constructor & Destructor Documentation

◆ VFS_datastore_cache_entry()

VFS_datastore_cache_entry::VFS_datastore_cache_entry ( bool  debug,
int  flushInterval,
int  expireInterval,
bool  raw = false 
)
explicit

Construct the cache entry.

Parameters
debugVerbose debug output
flushIntervalInterval to flush to storage medium, provided by a storage VFS_node like VFS_HD, but could be set uniquely per cache entry. In milliseconds.
expireIntervalInterval to expire a cache entry, which will cause it to be removed from the cache. In milliseconds.
rawWhether or not to treat this data as JSON or raw data. Useful for subclasses as a flag, but unused in this class.

On creation, the cache entry will start the flush timer and call touch().

Note
Creating a cache entry with flushInterval or expireInterval to 0 will cause it to never flush and never expire.

Definition at line 31 of file VFS_datastore.cpp.

◆ ~VFS_datastore_cache_entry()

VFS_datastore_cache_entry::~VFS_datastore_cache_entry ( )
virtual

Destroy the cache entry.

If it is _dirty or not _valid, a warning will be issued, but a flush() is not called. Subclasses may choose to flush().

Definition at line 57 of file VFS_datastore.cpp.

Member Function Documentation

◆ expired

void VFS_datastore_cache_entry::expired ( VFS_datastore_cache_entry )
signal

Signal emitted when a cache entry has expired and is no longer in use.

◆ flush()

virtual void VFS_datastore_cache_entry::flush ( )
protectedpure virtual

A pure virtual function that must be overridden in subclasses. This is the function that actually commits data to a storage medium.

Implemented in VFS_mongo_cache_entry, and VFS_HD_cache_entry.

◆ getData()

QJsonDocument VFS_datastore_cache_entry::getData ( )
virtual

Return the data from an entry.

Returns
The data as a QJsonDocument

Also touch() the cache entry, because this means it is in use and can expire later.

Definition at line 156 of file VFS_datastore.cpp.

◆ getRawData()

QByteArray VFS_datastore_cache_entry::getRawData ( )
virtual

Return the data from an entry.

Returns
The data as a QJsonDocument

Also touch() the cache entry, because this means it is in use and can expire later.

Definition at line 187 of file VFS_datastore.cpp.

◆ setData() [1/2]

void VFS_datastore_cache_entry::setData ( QByteArray  data)
virtual

Write raw data to the entry.

Parameters
dataThe data

The _dirty flag will be set, because the data has not been flush()ed yet.

Definition at line 170 of file VFS_datastore.cpp.

◆ setData() [2/2]

void VFS_datastore_cache_entry::setData ( QJsonObject  json)
virtual

Write data to the entry.

Parameters
jsonThe data

If a subclass chooses to use the raw flag, it will want to use setData(QByteArray).

The _dirty flag will be set, because the data has not been flush()ed yet.

Definition at line 135 of file VFS_datastore.cpp.

◆ size()

quint64 VFS_datastore_cache_entry::size ( )
Returns
The cache entry size

Definition at line 121 of file VFS_datastore.cpp.

◆ timerEvent

void VFS_datastore_cache_entry::timerEvent ( QTimerEvent *  event)
virtualslot

Either a flush or expire has happened.

Parameters
eventThe timer event

In either case, call flush() to commit data to a storage medium, or report an error if flush() was not possible.

If expired and flush was not possible, the expired() signal will not be emitted. This is a tricky case to deal with, because it implies that some other problem, like a full disk, is the culprit. At least the data here is not lost yet.

Definition at line 75 of file VFS_datastore.cpp.

◆ touch()

void VFS_datastore_cache_entry::touch ( )
protectedvirtual

Reset the expiration timer.

This will cause expiration to happen in the future. Another touch() will extend this.

Definition at line 215 of file VFS_datastore.cpp.

◆ touched

void VFS_datastore_cache_entry::touched ( )
signal

Signal emitted when a cache entry has made a change and should climb the cache queue.

◆ valid()

bool VFS_datastore_cache_entry::valid ( QString &  reason)
virtual
Parameters
reasonIf invalid, the reason will be written to this string.
Returns
The _valid flag value

A subclass must set an entry as _valid, based on whatever criteria it wants. By default all entries are _valid==false.

Reimplemented in VFS_mongo_cache_entry, and VFS_HD_cache_entry.

Definition at line 201 of file VFS_datastore.cpp.

Member Data Documentation

◆ _data

QJsonDocument VFS_datastore_cache_entry::_data
protected

The actual cache data.

Definition at line 32 of file VFS_datastore.h.

◆ _debug

bool VFS_datastore_cache_entry::_debug
protected

Debug flag, for verbose output.

Definition at line 39 of file VFS_datastore.h.

◆ _dirty

bool VFS_datastore_cache_entry::_dirty
protected

Changes have occurred but they are not commited to storage yet.

Definition at line 36 of file VFS_datastore.h.

◆ _expireID

int VFS_datastore_cache_entry::_expireID
protected

Timer ID for expire events.

Definition at line 43 of file VFS_datastore.h.

◆ _expireInterval

int VFS_datastore_cache_entry::_expireInterval
protected

Expire interval, in milliseconds.

Definition at line 44 of file VFS_datastore.h.

◆ _expireTimer

QBasicTimer VFS_datastore_cache_entry::_expireTimer
protected

The expiration timer.

Definition at line 45 of file VFS_datastore.h.

◆ _flushID

int VFS_datastore_cache_entry::_flushID
protected

Timer ID for flush events.

Definition at line 41 of file VFS_datastore.h.

◆ _flushInterval

int VFS_datastore_cache_entry::_flushInterval
protected

Flush interval, in milliseconds.

Definition at line 42 of file VFS_datastore.h.

◆ _key

QString VFS_datastore_cache_entry::_key

The cache entry key.

Definition at line 26 of file VFS_datastore.h.

◆ _raw

bool VFS_datastore_cache_entry::_raw
protected

A convenience flag used in subclasses. Not used by this class.

Definition at line 35 of file VFS_datastore.h.

◆ _rawData

QByteArray VFS_datastore_cache_entry::_rawData
protected

Raw binary data. Used if _raw=true.

Definition at line 33 of file VFS_datastore.h.

◆ _reason

QString VFS_datastore_cache_entry::_reason
protected

The reason this may be invalid. Set by a subclass.

Definition at line 38 of file VFS_datastore.h.

◆ _size

quint64 VFS_datastore_cache_entry::_size
protected

The size of the data. Always initialized to zero. Must be set in a subclass.

Definition at line 34 of file VFS_datastore.h.

◆ _valid

bool VFS_datastore_cache_entry::_valid
protected

Defaults to false. A subclass will determine if _valid is true, like for instance if an underlying file doesn't exist.

Definition at line 37 of file VFS_datastore.h.


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