put method
Add / Replace the cache value
for the specified key
.
key
: the keyvalue
: the valuedelegate
: 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);
}