put method

Future<void> put(
  1. K key,
  2. V value
)

Stores a value in the cache with the given key (async version with eviction).

Implementation

Future<void> put(K key, V value) async {
  final entry = CacheEntry<K, V>(
    key: key,
    value: value,
  );

  // Check if we need to evict an item
  final currentSize = await _storage.size;
  if (currentSize >= _maxSize && !await _storage.containsKey(key)) {
    await _evictItem();
  }

  await _storage.put(key, entry);
}