getAndPut method

  1. @override
Future getAndPut(
  1. String key,
  2. dynamic value, {
  3. Duration? expiryDuration,
})
override

Associates the specified value with the specified key in this cache, returning an existing value if one existed. If the cache previously contained a mapping for the key, the old value is replaced by the specified value

  • key: key with which the specified value is to be associated
  • value: value to be associated with the specified key

The previous value is returned, or null if there was no value associated with the key previously.

Implementation

@override
Future<dynamic> getAndPut(String key, dynamic value,
    {Duration? expiryDuration}) {
  return _primary.getAndPut(key, value).then((value) {
    if (value == null) {
      return _secondary.getAndPut(key, value);
    }

    _secondary.put(key, value);

    return Future.value(value);
  });
}