set method

Future<Null> set(
  1. K key,
  2. V value
)

Sets the value associated with key. The Future completes with null when the operation is complete.

Setting the same key should make that key the latest key in _cache.

Implementation

Future<Null> set(K key, V value) async {
  if (_inflightSet.containsKey(key)) {
    _inflightSet[key]!._completer.complete(value);
    _inflightSet.remove(key);
  }
  // Removing the key and adding it again will make it be last in the
  // iteration order.
  if (_cache.containsKey(key)) {
    _cache.remove(key);
  }
  _cache[key] = CacheEntry(value, clock.now());
  if (_cache.length > sizeLimit) {
    removeFirst();
  }
}