refresh method

  1. @override
Future<void> refresh(
  1. String key,
  2. Map<String, dynamic> data
)
override

Updates the data located at key in both the level 2 cache and in-memory cache.

Throws JsonCacheException to indicate operation failure.

Implementation

@override
Future<void> refresh(String key, Map<String, dynamic> data) async {
  // ATTENTION: It is safer to copy the content of [data] before calling an
  // asynchronous method that will copy it to avoid data races. For example,
  // if the client code clears [data] right after passing it to this method,
  // there's a high chance of having the level 2 cache and this object with
  // different contents.
  //
  // In Dart, synchronous code cannot be interrupted, so there is no need to
  // protect it using mutual exclusion.
  final copy = Map<String, dynamic>.of(data);
  await _mutex.protectWrite(() async {
    await _level2.refresh(key, copy);
    _memory[key] = copy;
  });
}