get method

  1. @override
Future<T?> get(
  1. String key
)
override

Returns the stash value for the specified key

  • key: the key

Implementation

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

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

  // Gets the entry from the storage
  return _getStorageEntry(key).then((entry) {
    // Does this entry exists ?
    if (entry == null) {
      return Future<T?>.value();
    } else {
      return _getEntryValue(entry, now);
    }
  }).then(posGet);
}