put method

Future<void> put(
  1. DtoUser user, {
  2. bool ignoreVersion = false,
})

Puts the provided user into the local storage.

Implementation

Future<void> put(DtoUser user, {bool ignoreVersion = false}) async {
  Log.trace('put(${user.value.id}, $ignoreVersion)', '$runtimeType');

  // If the provided [user] doesn't exist in the [users] yet, then we should
  // lock the [mutex] to ensure [get] doesn't invoke remote while [put]ting.
  if (users.containsKey(user.value.id)) {
    await _putUser(user, ignoreVersion: ignoreVersion);
  } else {
    Mutex? mutex = _locks[user.value.id];
    if (mutex == null) {
      mutex = Mutex();
      _locks[user.value.id] = mutex;
    }

    await mutex.protect(() async {
      await _putUser(user, ignoreVersion: ignoreVersion);
    });
  }
}