set method
Stores a cache entry with the given key.
If an entry with the same key already exists, it should be replaced.
Implementations may enforce size limits and evict old entries as needed (e.g., LRU eviction).
Implementation
@override
void set(String key, CacheEntry entry) {
// If key already exists, remove it from access order
if (_cache.containsKey(key)) {
_accessOrder.remove(key);
}
// Add/update entry
_cache[key] = entry;
_accessOrder.addLast(key);
// LRU eviction if size limit exceeded
if (maxSize != null && _cache.length > maxSize!) {
final oldestKey = _accessOrder.removeFirst();
_cache.remove(oldestKey);
}
}