evict method
Deletes stale state, with its version key, and returns a new set of the state keys it deleted. A key's use time is when its store last hydrated from it or wrote it (kept as the file's modification time).
olderThandrops every key not used for that long.maxEntriesthen keeps only that many keys, the most recently used.wherelimits both to the keys it accepts; other keys are never evicted and do not count towardsmaxEntries.keepLivespares, likewhere, the keys of live stores.
Live stores of evicted keys stop persisting.
Implementation
Future<Set<String>> evict({
Duration? olderThan,
int? maxEntries,
bool Function(String key)? where,
bool keepLive = false,
}) async {
checkEvictArguments(olderThan: olderThan, maxEntries: maxEntries);
// Under the lock, so use times queued by [markUsed] land first.
final doomed = await _locked('evict', () async {
// [keys] leaves out the keys a queued delete hides, as
// `HydratedStorage.evict` does: they are going anyway, and must not
// take a place [maxEntries] keeps.
final accepted = evictionCandidates(keys, where);
await _loadUseTimes(accepted);
return evictionsAmong(
accepted,
usedAt: _usedAtOf,
now: _clock().millisecondsSinceEpoch,
olderThan: olderThan,
maxEntries: maxEntries,
live: keepLive ? () => HydratedMobX.liveTokens(storage: this) : null,
// A delete may have been queued since the candidates were listed,
// by [where] or while the use times loaded.
gone: _pending.hides,
);
});
if (doomed.isEmpty) return doomed;
await HydratedMobX.clearAll(storage: this, where: doomed.contains);
return doomed;
}