getObjectsOverCapacity method

  1. @override
Future<List<CacheObject>> getObjectsOverCapacity(
  1. int capacity
)
override

Gets the list of CacheObject that can be removed if the repository is over capacity.

The exact implementation is up to the repository, but implementations should return a preferred list of items. For example, the least recently accessed

Implementation

@override
Future<List<CacheObject>> getObjectsOverCapacity(int capacity) async {
  final allSorted = _cacheObjects.values.toList()
    ..sort((c1, c2) => c1.touched!.compareTo(c2.touched!));
  if (allSorted.length <= capacity) return [];
  return allSorted.getRange(0, allSorted.length - capacity).toList();
}