From 5ee441cba8fe3527fcced2dfc6c29f0290f5c12a Mon Sep 17 00:00:00 2001 From: Erica Fischer Date: Wed, 27 Sep 2023 15:32:58 -0700 Subject: [PATCH] Limit the size of the cache --- tile-join.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tile-join.cpp b/tile-join.cpp index a39acda4e..e321a5970 100644 --- a/tile-join.cpp +++ b/tile-join.cpp @@ -437,7 +437,10 @@ struct reader { std::vector> tiles_at_maxzoom_so_far; std::vector> overzoomed_tiles; bool overzoom_consumed_at_this_zoom = false; + + // parent tile cache std::map overzoom_cache; + size_t overzoom_cache_seq; // for iterating mbtiles sqlite3 *db = NULL; @@ -761,6 +764,17 @@ struct reader { mvt_tile source; auto f = overzoom_cache.find(parent_tile); if (f == overzoom_cache.end()) { + if (overzoom_cache.size() > 1000) { + // evict something to make room + + auto to_erase = overzoom_cache.begin(); + for (size_t i = 0; i < overzoom_cache_seq; i++) { + ++to_erase; + } + + overzoom_cache.erase(to_erase); + } + source = get_tile(parent_tile); overzoom_cache.emplace(parent_tile, source); static std::atomic count(0);