summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bin/render.cpp4
-rw-r--r--include/mbgl/storage/default_file_source.hpp7
-rw-r--r--platform/android/src/native_map_view.cpp4
-rw-r--r--platform/android/src/native_map_view.hpp2
-rw-r--r--platform/default/default_file_source.cpp19
-rw-r--r--platform/ios/src/MGLMapView.mm5
-rw-r--r--platform/linux/main.cpp9
-rw-r--r--platform/osx/src/MGLMapView.mm5
-rw-r--r--src/mbgl/storage/sqlite_cache.hpp (renamed from include/mbgl/storage/sqlite_cache.hpp)0
9 files changed, 26 insertions, 29 deletions
diff --git a/bin/render.cpp b/bin/render.cpp
index 71f74b043c..26fd06d507 100644
--- a/bin/render.cpp
+++ b/bin/render.cpp
@@ -6,7 +6,6 @@
#include <mbgl/platform/default/headless_view.hpp>
#include <mbgl/platform/default/headless_display.hpp>
#include <mbgl/storage/default_file_source.hpp>
-#include <mbgl/storage/sqlite_cache.hpp>
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunknown-pragmas"
@@ -65,8 +64,7 @@ int main(int argc, char *argv[]) {
using namespace mbgl;
util::RunLoop loop;
- SQLiteCache cache(cache_file);
- DefaultFileSource fileSource(&cache);
+ DefaultFileSource fileSource(cache_file);
// Try to load the token from the environment.
if (!token.size()) {
diff --git a/include/mbgl/storage/default_file_source.hpp b/include/mbgl/storage/default_file_source.hpp
index 3689b9e932..83ea4adf5d 100644
--- a/include/mbgl/storage/default_file_source.hpp
+++ b/include/mbgl/storage/default_file_source.hpp
@@ -5,16 +5,17 @@
namespace mbgl {
-class FileCache;
-
class DefaultFileSource : public FileSource {
public:
- DefaultFileSource(FileCache*, const std::string& root = "");
+ DefaultFileSource(const std::string& cachePath = ":memory:", const std::string& root = "");
~DefaultFileSource() override;
void setAccessToken(const std::string&);
std::string getAccessToken() const;
+ void setMaximumCacheSize(uint64_t size);
+ void setMaximumCacheEntrySize(uint64_t size);
+
std::unique_ptr<FileRequest> request(const Resource&, Callback) override;
private:
diff --git a/platform/android/src/native_map_view.cpp b/platform/android/src/native_map_view.cpp
index 30fdee81b9..96b48e12c6 100644
--- a/platform/android/src/native_map_view.cpp
+++ b/platform/android/src/native_map_view.cpp
@@ -75,8 +75,7 @@ NativeMapView::NativeMapView(JNIEnv *env, jobject obj_, float pixelRatio_, int a
return;
}
- fileCache = mbgl::SharedSQLiteCache::get(mbgl::android::cachePath + "/mbgl-cache.db");
- fileSource = std::make_unique<mbgl::DefaultFileSource>(fileCache.get());
+ fileSource = std::make_unique<mbgl::DefaultFileSource>(mbgl::android::cachePath + "/mbgl-cache.db");
map = std::make_unique<mbgl::Map>(*this, *fileSource, MapMode::Continuous);
float zoomFactor = map->getMaxZoom() - map->getMinZoom() + 1;
@@ -103,7 +102,6 @@ NativeMapView::~NativeMapView() {
map.reset();
fileSource.reset();
- fileCache.reset();
jint ret;
JNIEnv *env = nullptr;
diff --git a/platform/android/src/native_map_view.hpp b/platform/android/src/native_map_view.hpp
index 7b5473d48c..cc88403c39 100644
--- a/platform/android/src/native_map_view.hpp
+++ b/platform/android/src/native_map_view.hpp
@@ -4,7 +4,6 @@
#include <mbgl/map/map.hpp>
#include <mbgl/map/view.hpp>
#include <mbgl/util/noncopyable.hpp>
-#include <mbgl/storage/sqlite_cache.hpp>
#include <mbgl/storage/default_file_source.hpp>
#include <string>
@@ -91,7 +90,6 @@ private:
JNIEnv *renderEnv = nullptr;
// Ensure these are initialised last
- std::shared_ptr<mbgl::SQLiteCache> fileCache;
std::unique_ptr<mbgl::DefaultFileSource> fileSource;
std::unique_ptr<mbgl::Map> map;
};
diff --git a/platform/default/default_file_source.cpp b/platform/default/default_file_source.cpp
index b2ab5abd6c..d2bbce6002 100644
--- a/platform/default/default_file_source.cpp
+++ b/platform/default/default_file_source.cpp
@@ -1,19 +1,22 @@
#include <mbgl/storage/default_file_source.hpp>
#include <mbgl/storage/online_file_source.hpp>
+#include <mbgl/storage/sqlite_cache.hpp>
namespace mbgl {
class DefaultFileSource::Impl {
public:
- Impl(FileCache* cache, const std::string& root)
- : onlineFileSource(cache, root) {
+ Impl(const std::string& cachePath, const std::string& root)
+ : cache(SharedSQLiteCache::get(cachePath)),
+ onlineFileSource(cache.get(), root) {
}
+ std::shared_ptr<SQLiteCache> cache;
OnlineFileSource onlineFileSource;
};
-DefaultFileSource::DefaultFileSource(FileCache* cache, const std::string& root)
- : impl(std::make_unique<DefaultFileSource::Impl>(cache, root)) {
+DefaultFileSource::DefaultFileSource(const std::string& cachePath, const std::string& root)
+ : impl(std::make_unique<DefaultFileSource::Impl>(cachePath, root)) {
}
DefaultFileSource::~DefaultFileSource() = default;
@@ -26,6 +29,14 @@ std::string DefaultFileSource::getAccessToken() const {
return impl->onlineFileSource.getAccessToken();
}
+void DefaultFileSource::setMaximumCacheSize(uint64_t size) {
+ impl->cache->setMaximumCacheSize(size);
+}
+
+void DefaultFileSource::setMaximumCacheEntrySize(uint64_t size) {
+ impl->cache->setMaximumCacheEntrySize(size);
+}
+
std::unique_ptr<FileRequest> DefaultFileSource::request(const Resource& resource, Callback callback) {
return impl->onlineFileSource.request(resource, callback);
}
diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm
index 7fe040b0f1..4ee12942b4 100644
--- a/platform/ios/src/MGLMapView.mm
+++ b/platform/ios/src/MGLMapView.mm
@@ -16,7 +16,6 @@
#include <mbgl/map/mode.hpp>
#include <mbgl/platform/platform.hpp>
#include <mbgl/platform/darwin/reachability.h>
-#include <mbgl/storage/sqlite_cache.hpp>
#include <mbgl/storage/default_file_source.hpp>
#include <mbgl/storage/network_status.hpp>
#include <mbgl/util/geo.hpp>
@@ -154,7 +153,6 @@ public:
{
mbgl::Map *_mbglMap;
MBGLView *_mbglView;
- std::shared_ptr<mbgl::SQLiteCache> _mbglFileCache;
mbgl::DefaultFileSource *_mbglFileSource;
BOOL _opaque;
@@ -281,8 +279,7 @@ std::chrono::steady_clock::duration MGLDurationInSeconds(float duration)
NSString *libraryDirectory = [paths objectAtIndex:0];
fileCachePath = [libraryDirectory stringByAppendingPathComponent:@"cache.db"];
}
- _mbglFileCache = mbgl::SharedSQLiteCache::get([fileCachePath UTF8String]);
- _mbglFileSource = new mbgl::DefaultFileSource(_mbglFileCache.get());
+ _mbglFileSource = new mbgl::DefaultFileSource([fileCachePath UTF8String]);
// setup mbgl map
_mbglMap = new mbgl::Map(*_mbglView, *_mbglFileSource, mbgl::MapMode::Continuous);
diff --git a/platform/linux/main.cpp b/platform/linux/main.cpp
index 45f2b8defa..d6cf10fe70 100644
--- a/platform/linux/main.cpp
+++ b/platform/linux/main.cpp
@@ -5,7 +5,6 @@
#include <mbgl/platform/default/settings_json.hpp>
#include <mbgl/platform/default/glfw_view.hpp>
#include <mbgl/storage/default_file_source.hpp>
-#include <mbgl/storage/sqlite_cache.hpp>
#include <signal.h>
#include <getopt.h>
@@ -106,11 +105,9 @@ int main(int argc, char *argv[]) {
view = std::make_unique<GLFWView>(fullscreen, benchmark);
- mbgl::SQLiteCache cache("/tmp/mbgl-cache.db");
- cache.setMaximumCacheEntrySize(1 * 1024 * 1024); // 1 MB
- cache.setMaximumCacheSize(50 * 1024 * 1024); // 50 MB
-
- mbgl::DefaultFileSource fileSource(&cache);
+ mbgl::DefaultFileSource fileSource("/tmp/mbgl-cache.db");
+ fileSource.setMaximumCacheEntrySize(1 * 1024 * 1024); // 1 MB
+ fileSource.setMaximumCacheSize(50 * 1024 * 1024); // 50 MB
// Set access token if present
const char *token = getenv("MAPBOX_ACCESS_TOKEN");
diff --git a/platform/osx/src/MGLMapView.mm b/platform/osx/src/MGLMapView.mm
index 7646e524a3..7215963fb3 100644
--- a/platform/osx/src/MGLMapView.mm
+++ b/platform/osx/src/MGLMapView.mm
@@ -22,7 +22,6 @@
#import <mbgl/sprite/sprite_image.hpp>
#import <mbgl/storage/default_file_source.hpp>
#import <mbgl/storage/network_status.hpp>
-#import <mbgl/storage/sqlite_cache.hpp>
#import <mbgl/util/constants.hpp>
#import <mbgl/util/math.hpp>
#import <mbgl/util/std.hpp>
@@ -152,7 +151,6 @@ public:
/// Cross-platform map view controller.
mbgl::Map *_mbglMap;
MGLMapViewImpl *_mbglView;
- std::shared_ptr<mbgl::SQLiteCache> _mbglFileCache;
mbgl::DefaultFileSource *_mbglFileSource;
NSPanGestureRecognizer *_panGestureRecognizer;
@@ -248,8 +246,7 @@ public:
error:nil];
NSURL *cacheURL = [cacheDirectoryURL URLByAppendingPathComponent:@"cache.db"];
NSString *cachePath = cacheURL ? cacheURL.path : @"";
- _mbglFileCache = mbgl::SharedSQLiteCache::get(cachePath.UTF8String);
- _mbglFileSource = new mbgl::DefaultFileSource(_mbglFileCache.get());
+ _mbglFileSource = new mbgl::DefaultFileSource(cachePath.UTF8String);
_mbglMap = new mbgl::Map(*_mbglView, *_mbglFileSource, mbgl::MapMode::Continuous);
diff --git a/include/mbgl/storage/sqlite_cache.hpp b/src/mbgl/storage/sqlite_cache.hpp
index 6e79d44a33..6e79d44a33 100644
--- a/include/mbgl/storage/sqlite_cache.hpp
+++ b/src/mbgl/storage/sqlite_cache.hpp