summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThiago Marcos P. Santos <tmpsantos@gmail.com>2019-06-10 14:40:48 +0300
committerThiago Marcos P. Santos <tmpsantos@gmail.com>2019-06-12 18:54:26 +0300
commit0f0fd1400586219e61937ee852f654ca8cf9a45d (patch)
treec64bb1e823e470bad87b7d3f60a564d86ea1222f
parent844299f1c3b22eed4bf07c37052b3c2ea35e2564 (diff)
downloadqtlocation-mapboxgl-0f0fd1400586219e61937ee852f654ca8cf9a45d.tar.gz
[core] Add API for clearing tile cache
-rw-r--r--platform/default/include/mbgl/storage/offline_database.hpp5
-rw-r--r--platform/default/src/mbgl/storage/offline_database.cpp20
2 files changed, 25 insertions, 0 deletions
diff --git a/platform/default/include/mbgl/storage/offline_database.hpp b/platform/default/include/mbgl/storage/offline_database.hpp
index 3de829e635..4e9ffcf028 100644
--- a/platform/default/include/mbgl/storage/offline_database.hpp
+++ b/platform/default/include/mbgl/storage/offline_database.hpp
@@ -58,6 +58,11 @@ public:
// lookup, it will not get downloaded again.
std::exception_ptr invalidateTileCache();
+ // Clear the tile cache, freeing resources. This operation can be
+ // potentially slow because it will trigger a VACUUM on SQLite,
+ // forcing the database to move pages on the filesystem.
+ std::exception_ptr clearTileCache();
+
expected<OfflineRegions, std::exception_ptr> listRegions();
expected<OfflineRegion, std::exception_ptr> createRegion(const OfflineRegionDefinition&,
diff --git a/platform/default/src/mbgl/storage/offline_database.cpp b/platform/default/src/mbgl/storage/offline_database.cpp
index 0b3bcc049f..b60828d3a7 100644
--- a/platform/default/src/mbgl/storage/offline_database.cpp
+++ b/platform/default/src/mbgl/storage/offline_database.cpp
@@ -624,6 +624,26 @@ std::exception_ptr OfflineDatabase::invalidateTileCache() try {
return std::current_exception();
}
+std::exception_ptr OfflineDatabase::clearTileCache() try {
+ // clang-format off
+ mapbox::sqlite::Query query{ getStatement(
+ "DELETE FROM tiles "
+ "WHERE id NOT IN ("
+ " SELECT tile_id FROM region_tiles"
+ ")"
+ ) };
+ // clang-format on
+
+ query.run();
+
+ db->exec("PRAGMA incremental_vacuum");
+
+ return nullptr;
+} catch (const mapbox::sqlite::Exception& ex) {
+ handleError(ex, "clear tile cache");
+ return std::current_exception();
+}
+
std::exception_ptr OfflineDatabase::invalidateRegion(int64_t regionID) try {
{
// clang-format off