put method
Stores a value
in the cache with the given key
.
The value
is wrapped in a CacheItem object, which allows for optional expiry.
Throws a CacheException if there is an error storing the data.
Implementation
@override
Future<void> put(String key, CacheItem<dynamic> item) async {
final db = await database;
dynamic value = item.value;
if (enableEncryption) {
value = _encrypt(jsonEncode(item.toJson()));
}
await db.insert(
'cache',
{
'key': key,
'value': value,
'expiry': item.expiry?.millisecondsSinceEpoch,
},
conflictAlgorithm: ConflictAlgorithm.replace,
);
}