select method

  1. @override
CacheInfo? select(
  1. Iterable<CacheInfo?> entries,
  2. DateTime now
)
inherited

Finds the best eviction candidate based on the sampled entries. What distinguishes this approach from the classic data structures approach is that an CacheInfo contains metadata (e.g. usage information) which can be used for making policy decisions, while generic data structures do not. It is expected that implementations will take advantage of that metadata.

  • entries: A list of non nullable sample entries to consider
  • now: The current time

Returns the CacheInfo of the entry that should be evicted or null if the entry list is empty

Implementation

@override
CacheInfo? select(Iterable<CacheInfo?> entries, DateTime now) {
  CacheInfo? selectedEntry;
  for (var entry in entries) {
    if (entry != null) {
      // Prefer the expired entries
      if (entry.isExpired(now)) {
        return entry;
      }
      if (selectedEntry == null || selectEntry(entry, selectedEntry, now)) {
        selectedEntry = entry;
      }
    }
  }

  return selectedEntry;
}