diff options
-rw-r--r-- | platform/default/include/mbgl/storage/offline_database.hpp | 5 | ||||
-rw-r--r-- | platform/default/src/mbgl/storage/offline_database.cpp | 20 |
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 |