clean method
Cleans the cache, i.e. removes enough cache items to meet sizeLimit
.
If sizeLimit
isn't provided, the size of the Cachette is used, which
is the most likely use case.
policy
can be used to override the Cachette's eviction policy.
Implementation
Result<int, CachetteError> clean({int? sizeLimit, EvictionPolicy? policy}) {
sizeLimit ??= size;
policy ??= evictionPolicy;
int toEvict = length - sizeLimit;
if (toEvict < 1) {
return Result.ok(0);
}
if (policy == EvictionPolicy.dontEvict) {
return Result.error(CacheFullError());
}
List<K> keys = gather(policy, toEvict);
return _evictMany(keys);
}