trimCache static method
Evicts least-recently-used cache entries until the cache fits cacheMaxBytes.
Implementation
static Future<void> trimCache() async {
final _BucketIndex? index = _indexes[UStorageBucket.cache];
if (index == null || index.usage <= cacheMaxBytes) return;
final List<UStorageEntry> byAge = index.entries.values.toList()..sort((UStorageEntry a, UStorageEntry b) => a.accessed.compareTo(b.accessed));
int usage = index.usage;
for (final UStorageEntry entry in byAge) {
if (usage <= cacheMaxBytes) break;
usage -= entry.size;
await remove(entry.key, bucket: UStorageBucket.cache);
}
}