Repository navigation
Replace DiskLruCache with a small built-in tile cache - #58
Conversation
- Store one file per tile with the bytes as sent by the server, instead of re-encoding every tile as PNG - Decode disk hits with RGB_565 like downloads, halving their memory - Expire tiles after 7 days, but show the old tile when the download fails, retried with the existing backoff - Look up the disk cache before taking a download permit - Write through a temp file and rename, trim least recently used tiles - Delete the old DiskLruCache directory on first use - Remove the com.jakewharton:disklrucache dependency Fixes #57
|
4 findings on commit 500606c
|
- Prefetch now also downloads expired fallback tiles again, through needsDownload() shared with the visible tiles - Forget the stale mark of a tile when the memory cache evicts it - Check for a changed tile source before reading the disk cache
|
Fixed 1 to 3 in f36f2a5. Prefetch and visible tiles now share needsDownload(), the stale mark is dropped on LRU eviction, and the source check runs before the disk read. Leaving 4 as is: trim() returns right away unless the cache is over 50MB, and then deletes down to 45MB, so the full scan runs about once per 5MB of new tiles, not on every put. Keeping a sorted index instead would bring back the journal we just removed. |
Fixes #57
DiskLruCache 2.0.2 is from 2013 and archived. This replaces it with
DiskTileCachewriting one file per tile (cacheDir/tiles2/<source>/<z>_<x>_<y>.tile), which also fixes how we used it.Disk cache
cache/tilesdirectory of DiskLruCache is deleted on first useExpiry and backoff
TileRetryTracker, so it's retried with the existing 2s to 60s backoff and replaced once the network is backMapController
TileCache.put(tile, bitmap)andDiskTileCache.put(tile, bitmap)still work and encode PNG, but the download path uses the new overloads with the original bytes.Tests: 18 new tests (DiskTileCacheTest, TileCacheTest and a new MapControllerTileLoadingTest that drives the real download path with a mocked server and a fake clock). 479 tests pass, coverage 82%.
I couldn't do the manual offline check on an emulator, because TLS to tile.openstreetmap.org fails on my machine's network (on main too). The loading order is covered by MapControllerTileLoadingTest instead.