cache method
Caches a value with a given key.
If cacheDuration is set, the entry will automatically expire after
that duration. Re-caching an existing key cancels its previous
expiration timer so the new entry's own expiration applies.
Implementation
void cache(String key, T value, {Duration? cacheDuration}) {
_expirationTimers.remove(key)?.cancel();
_cache[key] = _CachedItem(value, cacheDuration);
if (cacheDuration != null && cacheDuration > Duration.zero) {
_expirationTimers[key] = Timer(cacheDuration, () => _evict(key));
} else if (cacheDuration != null) {
// Zero/negative duration: treat as already expired.
_evict(key);
}
}