purge method

TreeReferenceMap<K, V> purge()

Remove all invalidKeys.

Implementation

TreeReferenceMap<K, V> purge() {
  var changed = false;
  if (keepPurgedEntries) {
    revalidatePurgedEntries();
    checkPurgedEntriesTimeout();

    var invalidKeys = this.invalidKeys;
    if (invalidKeys.isEmpty) return this;

    var purged = _purged ?? <K, MapEntry<DateTime, V>>{};
    _purged = purged;

    for (var k in invalidKeys) {
      var val = _map.remove(k);
      _purgedEntriesCount++;
      changed = true;
      if (val != null) {
        purged[k] = MapEntry(DateTime.now(), val);
      }
    }

    checkPurgeEntriesLimit();
  } else {
    for (var k in invalidKeys) {
      _map.remove(k);
      _purgedEntriesCount++;
      changed = true;
    }
  }

  if (changed) {
    _expireCache();
  }

  return this;
}