write method
Implementation
@override
Future<void> write(String key, Object? value, Duration? ttl) async {
await initialize();
final encoded = _encode(key, value);
final expiresAt =
ttl == null ? null : DateTime.now().add(ttl).millisecondsSinceEpoch;
await database.execute(
// Delete-then-insert rather than an upsert: ON CONFLICT is SQLite and
// Postgres syntax, ON DUPLICATE KEY is MySQL's, and the adapter has to
// run on all three.
'DELETE FROM $tableName WHERE cache_key = ?',
<Object?>[key],
);
await database.execute(
'INSERT INTO $tableName (cache_key, value, expires_at) '
'VALUES (?, ?, ?)',
<Object?>[key, encoded, expiresAt],
);
}