flush method

Future<void> flush()

Persists every dirty entry to the backing store and clears the dirty set. A store failure aborts the flush; already-written keys stay clean, the failing key and any after it remain dirty for the next attempt. Audited: 2026-06-12 11:26 EDT

Implementation

Future<void> flush() async {
  // Iterate cache entries (typed V, no cast) filtered to the dirty set, and
  // snapshot to a list so a concurrent put during the awaits is not lost.
  final List<MapEntry<K, V>> pending = <MapEntry<K, V>>[
    for (final MapEntry<K, V> e in _cache.entries)
      if (_dirty.contains(e.key)) e,
  ];
  for (final MapEntry<K, V> e in pending) {
    await _store(e.key, e.value);
    _dirty.remove(e.key);
  }
}