put method

Future<void> put(
  1. String key,
  2. Object? value, {
  3. Duration? ttl,
  4. DateTime? expiresAt,
  5. SyncMode? sync,
})

Stores value under key.

ttl (relative) or expiresAt (absolute) make the entry expire; when both are given expiresAt wins. sync overrides the database's sync mode for this write when it is stronger than the default.

Throws InvalidKeyException for a reserved or empty key and SerializationException when value cannot be encoded.

Implementation

Future<void> put(
  String key,
  Object? value, {
  Duration? ttl,
  DateTime? expiresAt,
  SyncMode? sync,
}) {
  _ensureOpen();
  return _track(
    () => _applyMutations(<_Mutation>[
      _Mutation.put(key, value, _resolveExpiry(ttl, expiresAt)),
    ], sync: sync),
  );
}