evictStaleToFit method
Evicts the oldest ids not in placed until a prospective addition fits.
The returned ids are in eviction order. If placed itself plus the
prospective addition exceeds the policy, every stale entry is removed and
canFit remains false; callers can then drop the excess new content.
Implementation
List<String> evictStaleToFit(
Set<String> placed, {
int additionalEntries = 0,
int additionalBytes = 0,
}) {
if (canFit(
additionalEntries: additionalEntries,
additionalBytes: additionalBytes,
)) {
return const <String>[];
}
final evicted = <String>[];
for (final entry in _byteLengths.entries.toList(growable: false)) {
if (canFit(
additionalEntries: additionalEntries,
additionalBytes: additionalBytes,
)) {
break;
}
if (placed.contains(entry.key)) continue;
_byteLengths.remove(entry.key);
_totalBytes -= entry.value;
evicted.add(entry.key);
}
return evicted;
}