get method
Retrieves a cache entry by key. If allowStale is true, returns entries within
the Stale-While-Revalidate or Stale-If-Error windows.
Implementation
@override
Future<CacheEntry?> get(String key, {bool allowStale = false}) async {
final entry = _entries[key];
if (entry == null) {
_misses++;
return null;
}
// Check expiration
if (entry.isExpired()) {
_expiredCount++;
_misses++;
await delete(key);
return null;
}
// If not fresh and not allowing stale:
if (!entry.isFresh() && !allowStale && !entry.isStaleWhileRevalidate()) {
_misses++;
return null;
}
_hits++;
// True LRU: Move accessed entry to the tail of the linked hash map (most recently used)
_entries.remove(key);
_entries[key] = entry;
return entry;
}