aboutsummaryrefslogtreecommitdiff
path: root/src/cachehandler.hpp
blob: ca782bb6f0aa663a4177c6f80f49101d4bad37d1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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