summaryrefslogtreecommitdiff
path: root/src/mbgl/storage/sqlite_cache.hpp
blob: b5a7cbcc0706b0a8312f55f7aac2db686860e622 (plain)
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
#ifndef MBGL_STORAGE_DEFAULT_SQLITE_CACHE
#define MBGL_STORAGE_DEFAULT_SQLITE_CACHE

#include <mbgl/util/noncopyable.hpp>
#include <mbgl/util/chrono.hpp>

#include <functional>
#include <memory>
#include <string>

namespace mbgl {

class Resource;
class Response;
class WorkRequest;

namespace util {
template <typename T> class Thread;
} // namespace util

class SQLiteCache : private util::noncopyable {
public:
    static std::shared_ptr<SQLiteCache> getShared(const std::string &path = ":memory:");

    SQLiteCache(const std::string &path = ":memory:");
    ~SQLiteCache();

    void setMaximumCacheSize(uint64_t size);
    void setMaximumCacheEntrySize(uint64_t size);

    using Callback = std::function<void(std::unique_ptr<Response>)>;

    std::unique_ptr<WorkRequest> get(const Resource&, Callback);
    void put(const Resource&, const Response&);

    class Impl;

private:
    const std::unique_ptr<util::Thread<Impl>> thread;
};

} // namespace mbgl

#endif