template<class T>
QgsAbstractContentCache class
Abstract base class for file content caches, such as SVG or raster image caches.
Contents
Handles trimming the maximum cached content size to a desired limit, fetching remote content (via HTTP), and automatically invalidating cached content when the corresponding file is changed.
Base classes
- class QgsAbstractContentCacheBase
- A QObject derived base class for QgsAbstractContentCache.
Constructors, destructors, conversion operators
- QgsAbstractContentCache(QObject* parent = nullptr, const QString& typeString = QString(), long maxCacheSize = 20000000, int fileModifiedCheckTimeout = 30000)
- Constructor for QgsAbstractContentCache, with the specified parent object.
Protected functions
- auto findExistingEntry(T* entryTemplate) -> T*
- Returns the existing entry from the cache which matches entryTemplate (deleting entryTemplate when done), or if no existing entry is found then entryTemplate is transferred to the cache and returned.
- auto getContent(const QString& path, const QByteArray& missingContent, const QByteArray& fetchingContent) const -> QByteArray
- Gets the file content corresponding to the given path.
- void onRemoteContentFetched(const QString& url, bool success) override
- Triggered after remote content (i.e.
- void trimToMaximumSize()
- Removes the least used cache entries until the maximum cache size is under the predefined size limit.
Protected variables
- long mMaxCacheSize
- Maximum cache size.
- long mTotalSize
- Estimated total size of all cached content.
Function documentation
template<class T>
QgsAbstractContentCache<T>:: QgsAbstractContentCache(QObject* parent = nullptr,
const QString& typeString = QString(),
long maxCacheSize = 20000000,
int fileModifiedCheckTimeout = 30000)
Constructor for QgsAbstractContentCache, with the specified parent object.
The maxCacheSize argument dictates the maximum allowable total size of the cache, in bytes. This in turn dictates the maximum allowable size for caching individual entries.
The fileModifiedCheckTimeout dictates the minimum time (in milliseconds) between consecutive checks of whether a file's content has been modified (and existing cache entries should be discarded).
template<class T>
T* QgsAbstractContentCache<T>:: findExistingEntry(T* entryTemplate) protected
Returns the existing entry from the cache which matches entryTemplate (deleting entryTemplate when done), or if no existing entry is found then entryTemplate is transferred to the cache and returned.
I.e. either way ownership of entryTemplate is transferred by calling this method.
If an existing entry was found, then the corresponding file MAY be rechecked for changes (only if a suitable time has occurred since the last check).
template<class T>
QByteArray QgsAbstractContentCache<T>:: getContent(const QString& path,
const QByteArray& missingContent,
const QByteArray& fetchingContent) const protected
Gets the file content corresponding to the given path.
path may be a local file, remote (HTTP) url, or a base 64 encoded string (with a "base64:" prefix).
The missingContent byte array is returned if the path could not be resolved or is broken. If the path corresponds to a remote URL, then fetchingContent will be returned while the content is in the process of being fetched.
template<class T>
void QgsAbstractContentCache<T>:: onRemoteContentFetched(const QString& url,
bool success) override protected
Triggered after remote content (i.e.
HTTP linked content at the given url) has been fetched.
The success argument will be true if the content was successfully fetched, or false if it was not fetched successfully.