Detect config drift in cached tile providers and replace stale instances

When a user edits a tile type's URL template, max zoom, or API key
without changing IDs, the cached DeflockTileProvider would keep the old
frozen config. Now _getOrCreateProvider() computes a config fingerprint
and replaces the provider when drift is detected.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Doug Borg
2026-03-04 10:12:49 -07:00
parent f3f40f36ef
commit 91e5177056
7 changed files with 197 additions and 13 deletions
+5 -3
View File
@@ -47,7 +47,7 @@ class ProviderTileCacheStore implements MapCachingProvider {
@override
Future<CachedMapTile?> getTile(String url) async {
final key = _keyFor(url);
final key = keyFor(url);
final tileFile = File(p.join(cacheDirectory, '$key.tile'));
final metaFile = File(p.join(cacheDirectory, '$key.meta'));
@@ -90,7 +90,7 @@ class ProviderTileCacheStore implements MapCachingProvider {
}) async {
await _ensureDirectory();
final key = _keyFor(url);
final key = keyFor(url);
final tileFile = File(p.join(cacheDirectory, '$key.tile'));
final metaFile = File(p.join(cacheDirectory, '$key.meta'));
@@ -158,7 +158,8 @@ class ProviderTileCacheStore implements MapCachingProvider {
}
/// Generate a cache key from URL using UUID v5 (same as flutter_map built-in).
static String _keyFor(String url) => _uuid.v5(Namespace.url.value, url);
@visibleForTesting
static String keyFor(String url) => _uuid.v5(Namespace.url.value, url);
/// Estimate total cache size (lazy, first call scans directory).
Future<int> _getEstimatedSize() async {
@@ -301,6 +302,7 @@ class ProviderTileCacheStore implements MapCachingProvider {
}
_estimatedSize = null;
_directoryReady = null; // Allow lazy re-creation
_lastPruneCheck = null; // Reset throttle so next write can trigger eviction
}
/// Get the current estimated cache size in bytes.