length method

  1. @override
FutureOr<int> length({
  1. Duration? timeout,
  2. bool refresh = false,
})
override

Returns keys length.

Implementation

@override
FutureOr<int> length({Duration? timeout, bool refresh = false}) {
  var now = DateTime.now();

  if (refresh) {
    var length = _sharedMap.length();
    return _cacheKeysLength(length, now);
  }

  var keysLengthCached = _keysLengthCached;
  if (keysLengthCached != null) {
    timeout ??= this.timeout;

    var elapsedTime = now.difference(keysLengthCached.$1);
    if (elapsedTime <= timeout) {
      return keysLengthCached.$2;
    }
  }

  var lengthAsync = _lengthAsync;
  if (lengthAsync != null) {
    return lengthAsync;
  }

  var length = _sharedMap.length();
  return _cacheKeysLength(length, now);
}