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-13 22:28:16 +0300
commit32e0b7beec8ee1229cc6b1b1a4b857a459547b55 (patch)
tree621de8c60442bfa3b07abbf0ac4c576fdb5da721
parent427e6e7615ac6b6739b0ad830a3a18abd8b0ba21 (diff)
downloadqtlocation-mapboxgl-32e0b7beec8ee1229cc6b1b1a4b857a459547b55.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