From b8753509ff269fc21619fd2a7c8c30b237708e92 Mon Sep 17 00:00:00 2001 From: masaru87 <55574641+masaru87@users.noreply.github.com> Date: Fri, 24 Jul 2026 09:23:24 +0900 Subject: [PATCH 1/2] fix: evict from MBTILES_CACHE with for...of instead of for...in --- src/lib.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.ts b/src/lib.ts index 2905fb5..384cc6b 100644 --- a/src/lib.ts +++ b/src/lib.ts @@ -76,7 +76,7 @@ const getMBTilesInstance = (filename: string) => { if (MBTILES_LRU_INDEX.length >= MBTILES_CACHE_MAX) { const idxToDelete = MBTILES_LRU_INDEX.length - MBTILES_CACHE_MAX; const filenamesToDelete = MBTILES_LRU_INDEX.splice(0, idxToDelete); - for (const toDel in filenamesToDelete) { + for (const toDel of filenamesToDelete) { delete MBTILES_CACHE[toDel]; } } From 4ba26c2df69c662d633a5dabfff9a0ce3ae05d5d Mon Sep 17 00:00:00 2001 From: masaru87 <55574641+masaru87@users.noreply.github.com> Date: Fri, 24 Jul 2026 10:27:14 +0900 Subject: [PATCH 2/2] Fix off-by-one in LRU eviction so cache never exceeds MBTILES_CACHE_MAX When MBTILES_LRU_INDEX.length === MBTILES_CACHE_MAX, idxToDelete was 0, so nothing was evicted before the new entry was pushed and the cache grew to MAX+1 (staying one over from then on). Delete length-MAX+1 so the cache holds at MAX after insertion. --- src/lib.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.ts b/src/lib.ts index 384cc6b..c8109ec 100644 --- a/src/lib.ts +++ b/src/lib.ts @@ -74,7 +74,7 @@ const getMBTilesInstance = (filename: string) => { } if (MBTILES_LRU_INDEX.length >= MBTILES_CACHE_MAX) { - const idxToDelete = MBTILES_LRU_INDEX.length - MBTILES_CACHE_MAX; + const idxToDelete = MBTILES_LRU_INDEX.length - MBTILES_CACHE_MAX + 1; const filenamesToDelete = MBTILES_LRU_INDEX.splice(0, idxToDelete); for (const toDel of filenamesToDelete) { delete MBTILES_CACHE[toDel];