setValue method

void setValue(
  1. K key,
  2. V value
)

Adds the value to the cache under key.

If that key is already used, updates the value.

Implementation

void setValue(K key, V value) {
  final preexisting = _cache.containsKey(key);
  _cache[key] = value;

  if (!preexisting) {
    while (_cache.length > cacheSize) {
      final k = _cache.keys.first;
      _cache.remove(k);
    }
  }
}