save<T> method

  1. @override
Future<T> save<T>(
  1. String? correlationId,
  2. String key,
  3. dynamic value
)
override

Saves state into the store

  • correlationId (optional) transaction id to trace execution through call chain.
  • key a unique state key.
  • value a state value to store. Returns The value that was stored in the cache.

Implementation

@override
Future<T> save<T>(String? correlationId, String key, value) async {
  // Cleanup the stored states
  _cleanup();

  // Get the entry
  var entry = _states.containsKey(key) ? _states[key] : null;

  // Shortcut to remove entry from the cache
  if (value == null) {
    _states.remove(key);
    return value;
  }

  // Update the entry
  if (entry != null) {
    entry.setValue(value);
  }
  // Or create a new entry
  else {
    entry = StateEntry(key, value);
    _states[key] = entry;
  }

  return value;
}