diff options
| author | Mike Skec <skec@protonmail.ch> | 2021-01-08 15:34:54 +1100 |
|---|---|---|
| committer | Felix Queißner <felix@ib-queissner.de> | 2021-01-08 11:12:14 +0100 |
| commit | 35756f7a1b49f8d7aa603dd3bbe3c0a2c2d234a6 (patch) | |
| tree | c9a8fd3bc483623cd1fa294ee8eb866dd189b93c /src/cachehandler.hpp | |
| parent | 443da5e34a3b858a2a32c6ca6846e351fa11f389 (diff) | |
| download | kristall-35756f7a1b49f8d7aa603dd3bbe3c0a2c2d234a6.tar.gz | |
cache: item expiry and max item size
currently no total limit yet
Diffstat (limited to 'src/cachehandler.hpp')
| -rw-r--r-- | src/cachehandler.hpp | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/src/cachehandler.hpp b/src/cachehandler.hpp index 5aab2b6..a8bdb0f 100644 --- a/src/cachehandler.hpp +++ b/src/cachehandler.hpp @@ -9,6 +9,7 @@ #include <QString> #include <QByteArray> #include <QtGlobal> +#include <QDateTime> // Need a QString hash implementation for Qt versions below 5.14 #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) @@ -36,14 +37,18 @@ struct CachedPage int scroll_pos; + QDateTime time_cached; + // also: maybe compress page contents? May test // to see if it's worth it - CachedPage(const QUrl &url, const QByteArray &body, const MimeType &mime) - : url(url), body(body), mime(mime), scroll_pos(-1) + CachedPage(const QUrl &url, const QByteArray &body, + const MimeType &mime, const QDateTime &cached) + : url(url), body(body), mime(mime), scroll_pos(-1), time_cached(cached) {} }; +// TODO: move away from the 'unordered_map' type? typedef std::unordered_map<QString, std::shared_ptr<CachedPage>> CacheMap; class CacheHandler @@ -53,14 +58,18 @@ public: std::shared_ptr<CachedPage> find(QUrl const &url); - bool contains(QUrl const & url) const; + bool contains(QUrl const & url); + + int size(); + + void clean(); CacheMap const& getPages() const; private: std::shared_ptr<CachedPage> find(QString const &url); - bool contains(QString const & url) const; + bool contains(QString const & url); private: // In-memory cache storage. |
