get method

  1. @override
Future<T?> get(
  1. String key,
  2. {CacheEntryDelegate<T>? delegate}
)
override

Returns the cache value for the specified key.

  • key: the key
  • delegate: provides the caller a way of changing the CacheEntry before persistence

Implementation

@override
Future<T?> get(String key, {CacheEntryDelegate<T>? delegate}) {
  // #region Statistics
  Stopwatch? watch;
  Future<T?> Function(T? value) posGet = (T? value) => Future.value(value);
  if (statsEnabled) {
    watch = clock.stopwatch()..start();
    posGet = (T? value) {
      if (watch != null) {
        stats.increaseGets();
        stats.addGetTime(watch.elapsedMicroseconds);
        watch.stop();
      }

      return Future.value(value);
    };
  }
  // #endregion

  return _primary
      .get(key, delegate: delegate)
      .then((T? value) => value != null
          ? Future.value(value)
          : _secondary.get(key, delegate: delegate))
      .then(posGet);
}