get method

  1. @override
Future<V?> get(
  1. K k, {
  2. V? fallback,
})
override

Get value in cache or get fallback or null

Implementation

@override
Future<V?> get(K k, {V? fallback}) async {
  if (exist(k)) {
    return _cache[k]?.value;
  }

  if (_futures.containsKey(k)) {
    final res = await _futures[k]?.call();
    _cache[k] = _ManagedItem(
      key: k,
      value: res,
      expireDuration: expireDuration,
      onExpired: _expiredItem,
      reloadDuration: reloadDuration,
      onReload: _reloadItem,
    );

    return res;
  }

  if (fallback != null) {
    return fallback;
  }

  return null;
}