Create SharedSQLiteCache
This commit is contained in:
@@ -58,8 +58,8 @@ NativeMapView::NativeMapView(JNIEnv *env, jobject obj_, float pixelRatio_, int a
|
||||
pixelRatio(pixelRatio_),
|
||||
availableProcessors(availableProcessors_),
|
||||
totalMemory(totalMemory_),
|
||||
fileCache(mbgl::android::cachePath + "/mbgl-cache.db"),
|
||||
fileSource(&fileCache),
|
||||
fileCache(mbgl::SharedSQLiteCache::get(mbgl::android::cachePath + "/mbgl-cache.db")),
|
||||
fileSource(fileCache.get()),
|
||||
map(*this, fileSource, MapMode::Continuous) {
|
||||
mbgl::Log::Debug(mbgl::Event::Android, "NativeMapView::NativeMapView");
|
||||
|
||||
|
||||
@@ -90,7 +90,7 @@ private:
|
||||
size_t totalMemory = 0;
|
||||
|
||||
// Ensure these are initialised last
|
||||
mbgl::SQLiteCache fileCache;
|
||||
std::shared_ptr<mbgl::SQLiteCache> fileCache;
|
||||
mbgl::DefaultFileSource fileSource;
|
||||
mbgl::Map map;
|
||||
|
||||
|
||||
@@ -26,6 +26,16 @@ private:
|
||||
const std::unique_ptr<util::Thread<Impl>> thread;
|
||||
};
|
||||
|
||||
class SharedSQLiteCache : util::noncopyable {
|
||||
public:
|
||||
static std::shared_ptr<SQLiteCache> get(const std::string &path = ":memory:");
|
||||
|
||||
private:
|
||||
SharedSQLiteCache() {}
|
||||
|
||||
static std::weak_ptr<SQLiteCache> masterPtr;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -264,4 +264,16 @@ void SQLiteCache::Impl::refresh(const Resource& resource, int64_t expires) {
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<SQLiteCache> SharedSQLiteCache::get(const std::string &path) {
|
||||
std::shared_ptr<SQLiteCache> temp = masterPtr.lock();
|
||||
if (!temp) {
|
||||
temp.reset(new SQLiteCache(path));
|
||||
masterPtr = temp;
|
||||
}
|
||||
|
||||
return temp;
|
||||
}
|
||||
|
||||
std::weak_ptr<SQLiteCache> SharedSQLiteCache::masterPtr;
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user