cleanCacheTimedOut method

int cleanCacheTimedOut([
  1. Duration? timeout
])

Implementation

int cleanCacheTimedOut([Duration? timeout]) {
  timeout ??= this.timeout;
  if (timeout.inMilliseconds <= 0) return 0;

  var now = DateTime.now().millisecondsSinceEpoch;
  var timeoutMs = timeout.inMilliseconds;

  var removed = 0;
  for (var entry in _cache.values.toList()) {
    var elapsedTime = now - entry.accessTime;
    if (elapsedTime <= timeoutMs) continue;

    var memory = entry.memory;
    _removeEntry(entry.request);
    removed += memory;

    if (verbose) {
      _log(
        'Removed cached entry> memory: $memory ; timeout: $elapsedTime / $timeout',
      );
    }
  }

  if (verbose) _log('Total removed memory: $removed');

  return removed;
}