getOrLoad method

Future<V> getOrLoad(
  1. K key
)

Returns the cached value for key; on a miss, loads it once via the loader, stores it, and returns it. Simultaneous misses for key await the same load. Audited: 2026-06-12 11:26 EDT

Implementation

Future<V> getOrLoad(K key) {
  final V? cached = _cache.get(key);
  if (cached != null) return Future<V>.value(cached);
  final Future<V>? pending = _inFlight[key];
  if (pending != null) return pending;
  final Future<V> load = _load(key);
  _inFlight[key] = load;
  return load;
}