put method

  1. @override
Future<void> put(
  1. String key,
  2. T value, {
  3. CacheEntryDelegate<T>? delegate,
})
override

Add / Replace the cache value for the specified key.

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

Implementation

@override
Future<void> put(String key, T value, {CacheEntryDelegate<T>? delegate}) {
  // #region Statistics
  Stopwatch? watch;
  Future<void> Function(void) posPut = (_) => Future<void>.value();
  if (statsEnabled) {
    watch = clock.stopwatch()..start();
    posPut = (_) {
      stats.increasePuts();
      if (watch != null) {
        stats.addPutTime(watch.elapsedMicroseconds);
        watch.stop();
      }

      return Future<void>.value();
    };
  }
  // #endregion

  return _secondary
      .put(key, value, delegate: delegate)
      .then((_) => _primary.put(key, value, delegate: delegate))
      .then(posPut);
}