Remoto - VFS: VFS_mongo_cache_entry Class Reference
Remoto - VFS

A subclass of VFS_datastore_cache_entry, used for mongo database access. More...

#include <VFS_mongo.h>

Inheritance diagram for VFS_mongo_cache_entry:
VFS_datastore_cache_entry

Public Member Functions

 VFS_mongo_cache_entry (VFS_mongo *mongo, QString path, bool debug, int flushInterval, int expireInterval, bool create=false, bool container=false, QJsonObject createData=QJsonObject())
 
virtual ~VFS_mongo_cache_entry ()
 VFS_mongo_cache_entry destructor. More...
 
virtual bool isContainer ()
 Return the container-ness of this entry. More...
 
virtual bool valid (QString &reason)
 If the file or directory does not exist or is not readable, _valid is set to false. More...
 
- Public Member Functions inherited from VFS_datastore_cache_entry
 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 ()
 

Protected Member Functions

virtual void flush ()
 Actually write the document to the database. More...
 
- Protected Member Functions inherited from VFS_datastore_cache_entry
virtual void touch ()
 Reset the expiration timer. More...
 

Protected Attributes

bool _container
 The entry is a container. More...
 
VFS_mongo_mongo
 The VFS_mongo instance that owns this item's cache. More...
 
QString _path
 The path associated with this cache entry. More...
 
- Protected Attributes inherited from VFS_datastore_cache_entry
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...
 

Friends

class VFS_mongo
 

Additional Inherited Members

- Public Slots inherited from VFS_datastore_cache_entry
virtual void timerEvent (QTimerEvent *e)
 Either a flush or expire has happened. More...
 
- Signals inherited from VFS_datastore_cache_entry
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 Attributes inherited from VFS_datastore_cache_entry
QString _key
 The cache entry key. More...
 

Detailed Description

A subclass of VFS_datastore_cache_entry, used for mongo database access.

See also
VFS_datastore_cache_entry

Definition at line 19 of file VFS_mongo.h.

Constructor & Destructor Documentation

◆ VFS_mongo_cache_entry()

VFS_mongo_cache_entry::VFS_mongo_cache_entry ( VFS_mongo mongo,
QString  path,
bool  debug,
int  flushInterval,
int  expireInterval,
bool  create = false,
bool  container = false,
QJsonObject  createData = QJsonObject() 
)
explicit
Parameters
mongoThe VFS_mongo instance owning the cache of this object
pathThe path to database information, which may be a collection or a query or a single entry, or empty.
debugVerbose debug mode
flushIntervalInterval to flush to database, in milliseconds.
expireIntervalInterval to expire cache entries, in milliseconds.
createIf an entry with the path doesn't exist, create it.
containerIf the entry is meant to be a container
createDataIf creating, use this data to initialize it.

The mongocxx driver makes use of exceptions, which makes failures in this funtion a bit tricky to read.

This method will catch exceptions and set _vaild and _dirty as needed.

Definition at line 47 of file VFS_mongo.cpp.

◆ ~VFS_mongo_cache_entry()

VFS_mongo_cache_entry::~VFS_mongo_cache_entry ( )
virtual

VFS_mongo_cache_entry destructor.

Will call flush() if _dirty and _valid are true.

See also
VFS_datastore_cache_entry::~VFS_datastore_cache_entry()
VFS_HD_cache_entry

Definition at line 143 of file VFS_mongo.cpp.

Member Function Documentation

◆ flush()

void VFS_mongo_cache_entry::flush ( )
protectedvirtual

Actually write the document to the database.

If the entry is not _dirty, this immediately returns. If data cannot be written to disk, the entry is left _dirty and a _reason is recorded, and a VFS::CRITICAL() message is sent, on suspicion that the disk is full, the database is offline, or some other bad thing has happened.

On write success, _dirty is set to false, and the _size of the entry is updated.

Note
FIXME: The data size consumed in the cache should also be updated, but this is currently unimplemented.

Implements VFS_datastore_cache_entry.

Definition at line 191 of file VFS_mongo.cpp.

◆ isContainer()

bool VFS_mongo_cache_entry::isContainer ( )
virtual

Return the container-ness of this entry.

Returns
The value of _container

Definition at line 172 of file VFS_mongo.cpp.

◆ valid()

bool VFS_mongo_cache_entry::valid ( QString &  reason)
virtual

If the file or directory does not exist or is not readable, _valid is set to false.

Parameters
reasonIf invalid, the reason will be written to this string.
Returns
The _valid flag value

Reimplemented from VFS_datastore_cache_entry.

Definition at line 159 of file VFS_mongo.cpp.

Friends And Related Function Documentation

◆ VFS_mongo

friend class VFS_mongo
friend

Definition at line 23 of file VFS_mongo.h.

Member Data Documentation

◆ _container

bool VFS_mongo_cache_entry::_container
protected

The entry is a container.

Definition at line 35 of file VFS_mongo.h.

◆ _mongo

VFS_mongo* VFS_mongo_cache_entry::_mongo
protected

The VFS_mongo instance that owns this item's cache.

Definition at line 33 of file VFS_mongo.h.

◆ _path

QString VFS_mongo_cache_entry::_path
protected

The path associated with this cache entry.

Definition at line 34 of file VFS_mongo.h.


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