Files
MapLibreParticleLab/platform/default/sqlite_cache_impl.hpp
2015-12-27 18:15:33 +02:00

65 lines
1.6 KiB
C++

#ifndef MBGL_STORAGE_DEFAULT_SQLITE_CACHE_IMPL
#define MBGL_STORAGE_DEFAULT_SQLITE_CACHE_IMPL
#include <mbgl/storage/sqlite_cache.hpp>
#include <mbgl/util/chrono.hpp>
namespace mapbox {
namespace sqlite {
class Database;
class Statement;
}
}
namespace mbgl {
class SQLiteCache::Impl {
public:
explicit Impl(const std::string &path = ":memory:");
~Impl();
void setMaximumCacheSize(uint64_t size);
void setMaximumCacheEntrySize(uint64_t size);
void get(const Resource&, Callback);
void put(const Resource& resource, std::shared_ptr<const Response> response);
void refresh(const Resource& resource, Seconds expires);
private:
void initializeDatabase();
int cachePageSize();
uint64_t cacheHardSize();
uint64_t cacheSoftSize();
uint64_t softSize = 0;
bool softSizeDirty = true;
bool needsPruning();
void pruneEntries();
void createDatabase();
void createSchema();
int pageSize = 0;
uint64_t maximumCacheSize;
uint64_t maximumCacheEntrySize;
const std::string path;
std::unique_ptr<::mapbox::sqlite::Database> db;
std::unique_ptr<::mapbox::sqlite::Statement> getStmt;
std::unique_ptr<::mapbox::sqlite::Statement> putStmt;
std::unique_ptr<::mapbox::sqlite::Statement> refreshStmt;
std::unique_ptr<::mapbox::sqlite::Statement> countStmt;
std::unique_ptr<::mapbox::sqlite::Statement> freeStmt;
std::unique_ptr<::mapbox::sqlite::Statement> pruneStmt;
std::unique_ptr<::mapbox::sqlite::Statement> accessedStmt;
bool schema = false;
};
} // namespace mbgl
#endif