selectEntry method

  1. @override
bool selectEntry(
  1. CacheInfo entry,
  2. CacheInfo selectedEntry,
  3. DateTime now
)

Returns true if entry is a better candidate for eviction than the current selectedEntry

  • entry: The current entry
  • selectedEntry: The current selected entry
  • now: The current time

Implementation

@override
bool selectEntry(CacheInfo entry, CacheInfo selectedEntry, DateTime now) {
  int entryTicks = (now.microsecond - entry.creationTime.microsecond);
  int selectedEntryTicks =
      (now.microsecond - selectedEntry.creationTime.microsecond);
  if (entryTicks > 0 && selectedEntryTicks > 0) {
    double entryFactor = entry.hitCount / entryTicks;
    double selectedEntryFactor = selectedEntry.hitCount / selectedEntryTicks;

    return entryFactor < selectedEntryFactor;
  }

  return false;
}