set static method

Future<void> set(
  1. String key,
  2. dynamic value, {
  3. DateTime? expires,
  4. bool lazy = false,
})

Sets a value for a setting with the specified key.

Parameters:

  • key: A unique key for the setting. It is case-insensitive and will be stored in lowercase.
  • value: The value to set for the setting.

Implementation

static Future<void> set(String key, dynamic value, {DateTime? expires, bool lazy = false}) async {
  final data = KV()
    ..key = key.toLowerCase()
    ..value = serialize(value)
    ..expiresAt = expires;

  final db = await DB.instance();
  if (lazy) {
    db.writeTxn(() async => db.kVs.putByKey(data));
  } else {
    await db.writeTxn(() async => await db.kVs.putByKey(data));
  }

  _cache[key] = value;
}