From 35756f7a1b49f8d7aa603dd3bbe3c0a2c2d234a6 Mon Sep 17 00:00:00 2001 From: Mike Skec Date: Fri, 8 Jan 2021 15:34:54 +1100 Subject: cache: item expiry and max item size currently no total limit yet --- src/cachehandler.hpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'src/cachehandler.hpp') 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 #include #include +#include // 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> CacheMap; class CacheHandler @@ -53,14 +58,18 @@ public: std::shared_ptr 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 find(QString const &url); - bool contains(QString const & url) const; + bool contains(QString const & url); private: // In-memory cache storage. -- cgit v1.2.3