aboutsummaryrefslogtreecommitdiff
path: root/src/cachehandler.hpp
diff options
context:
space:
mode:
authorMike Skec <skec@protonmail.ch>2021-01-06 19:37:26 +1100
committerFelix Queißner <felix@ib-queissner.de>2021-01-06 10:51:18 +0100
commit2a9bb4fa6121de62d9e6ba06d9a109ba6d57f14c (patch)
tree7f2b49ca97071b003697ffeaaa904ce1dfe166d6 /src/cachehandler.hpp
parent24086fdfe92814c38da6d219916ee9d45d8ba581 (diff)
downloadkristall-2a9bb4fa6121de62d9e6ba06d9a109ba6d57f14c.tar.gz
cache code refactor
Diffstat (limited to 'src/cachehandler.hpp')
-rw-r--r--src/cachehandler.hpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/cachehandler.hpp b/src/cachehandler.hpp
new file mode 100644
index 0000000..ca782bb
--- /dev/null
+++ b/src/cachehandler.hpp
@@ -0,0 +1,48 @@
+#ifndef CACHEHANDLER_HPP
+#define CACHEHANDLER_HPP
+
+#include "mimeparser.hpp"
+#include <memory>
+#include <unordered_map>
+#include <QUrl>
+#include <QByteArray>
+
+struct CachedPage
+{
+ QUrl url;
+
+ QByteArray body;
+
+ MimeType mime;
+
+ int scroll_pos;
+
+ // 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)
+ {}
+};
+
+typedef std::unordered_map<QString, std::shared_ptr<CachedPage>> CacheMap;
+
+class CacheHandler
+{
+public:
+ void push(QUrl const & url, QByteArray const & body, MimeType const & mime);
+
+ std::shared_ptr<CachedPage> find(QString const &url);
+ std::shared_ptr<CachedPage> find(QUrl const &url);
+
+ bool contains(QString const & url) const;
+ bool contains(QUrl const & url) const;
+
+ CacheMap const& getPages() const;
+
+private:
+ // In-memory cache storage.
+ CacheMap page_cache;
+};
+
+#endif