summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2016-02-09 17:19:27 -0800
committerJohn Firebaugh <john.firebaugh@gmail.com>2016-02-10 15:40:20 -0800
commitdb3620c58f0c3351e26b0e3bcfd23ff414f829a1 (patch)
treee8def564e12307a997270b66a4ed46b68f5e13a4 /src
parent591012401072e63b89071787d90bf5ae4362dca1 (diff)
downloadqtlocation-mapboxgl-db3620c58f0c3351e26b0e3bcfd23ff414f829a1.tar.gz
[core] Implement an eviction policy for OfflineDatabase
When inserting an cached resource, or removing a region, remove least-recently used resources and tiles, not used by offline regions, until the used database size, as calculated by multiplying the number of in-use pages by the page size, is less than the maximum cache size minus 5 times the page size. In addition, OfflineDatabase may be configured to ignore cache puts of individual resources larger than a certain size. This policy is similar but not identical to the former SQLiteCache policy: * It accounts for offline, by exempting resources required by offline regions from eviction. * It must delete from two tables (resources and tiles), rather than one. Currently the strategy is naive: evict 50 rows at a time from each table. * It makes maximumCacheSize and maximumCacheEntrySize completely independent. The SQLiteCache implementation evicted when `usedSize > maximumCacheSize - 2 * maximumCacheEntrySize`. This evicts when `usedSize > maximumCacheSize - 5 * pageSize`. * It uses a non-unlimited default value for maximumCacheSize: 50 MB. We should have always had a limit in place; "a cache without an eviction policy is a resource leak".
Diffstat (limited to 'src')
-rw-r--r--src/mbgl/util/constants.cpp77
1 files changed, 47 insertions, 30 deletions
diff --git a/src/mbgl/util/constants.cpp b/src/mbgl/util/constants.cpp
index 0452dd19e5..047d7f3bd6 100644
--- a/src/mbgl/util/constants.cpp
+++ b/src/mbgl/util/constants.cpp
@@ -1,6 +1,12 @@
#include <mbgl/util/constants.hpp>
-const float mbgl::util::tileSize = 512.0f;
+#include <limits>
+
+namespace mbgl {
+
+namespace util {
+
+const float tileSize = 512.0f;
/*
* The maximum extent of a feature that can be safely stored in the buffer.
@@ -12,37 +18,48 @@ const float mbgl::util::tileSize = 512.0f;
* One bit is lost to support features extending past the extent on the right edge of the tile.
* This leaves us with 2^13 = 8192
*/
-const int32_t mbgl::util::EXTENT = 8192;
+const int32_t EXTENT = 8192;
+
+const double DEG2RAD = M_PI / 180.0;
+const double RAD2DEG = 180.0 / M_PI;
+const double M2PI = 2 * M_PI;
+const double EARTH_RADIUS_M = 6378137;
+const double LATITUDE_MAX = 85.05112878;
+const double PITCH_MAX = M_PI / 3;
+const double MIN_ZOOM = 0.0;
+const double MAX_ZOOM = 25.5;
-const double mbgl::util::DEG2RAD = M_PI / 180.0;
-const double mbgl::util::RAD2DEG = 180.0 / M_PI;
-const double mbgl::util::M2PI = 2 * M_PI;
-const double mbgl::util::EARTH_RADIUS_M = 6378137;
-const double mbgl::util::LATITUDE_MAX = 85.05112878;
-const double mbgl::util::PITCH_MAX = M_PI / 3;
-const double mbgl::util::MIN_ZOOM = 0.0;
-const double mbgl::util::MAX_ZOOM = 25.5;
+const uint64_t DEFAULT_MAX_CACHE_SIZE = 50 * 1024 * 1024;
+const uint64_t DEFAULT_MAX_CACHE_ENTRY_SIZE = std::numeric_limits<uint64_t>::max();
+
+} // namespace util
+
+namespace debug {
#if defined(DEBUG)
-const bool mbgl::debug::tileParseWarnings = false;
-const bool mbgl::debug::styleParseWarnings = false;
-const bool mbgl::debug::spriteWarnings = false;
-const bool mbgl::debug::renderWarnings = false;
-const bool mbgl::debug::renderTree = false;
-const bool mbgl::debug::labelTextMissingWarning = true;
-const bool mbgl::debug::missingFontStackWarning = true;
-const bool mbgl::debug::missingFontFaceWarning = true;
-const bool mbgl::debug::glyphWarning = true;
-const bool mbgl::debug::shapingWarning = true;
+const bool tileParseWarnings = false;
+const bool styleParseWarnings = false;
+const bool spriteWarnings = false;
+const bool renderWarnings = false;
+const bool renderTree = false;
+const bool labelTextMissingWarning = true;
+const bool missingFontStackWarning = true;
+const bool missingFontFaceWarning = true;
+const bool glyphWarning = true;
+const bool shapingWarning = true;
#else
-const bool mbgl::debug::tileParseWarnings = false;
-const bool mbgl::debug::styleParseWarnings = false;
-const bool mbgl::debug::spriteWarnings = false;
-const bool mbgl::debug::renderWarnings = false;
-const bool mbgl::debug::renderTree = false;
-const bool mbgl::debug::labelTextMissingWarning = false;
-const bool mbgl::debug::missingFontStackWarning = false;
-const bool mbgl::debug::missingFontFaceWarning = false;
-const bool mbgl::debug::glyphWarning = false;
-const bool mbgl::debug::shapingWarning = false;
+const bool tileParseWarnings = false;
+const bool styleParseWarnings = false;
+const bool spriteWarnings = false;
+const bool renderWarnings = false;
+const bool renderTree = false;
+const bool labelTextMissingWarning = false;
+const bool missingFontStackWarning = false;
+const bool missingFontFaceWarning = false;
+const bool glyphWarning = false;
+const bool shapingWarning = false;
#endif
+
+} // namespace debug
+
+} // namespace mbgl