get method
Retrieves the CacheItem associated with the given key
.
Returns null
if no value is found for the given key
.
Throws a CacheException if there is an error retrieving the data.
Implementation
@override
Future<CacheItem<dynamic>?> get(String key) async {
final db = await database;
final result = await db.query('cache', where: 'key = ?', whereArgs: [key]);
if (result.isEmpty) {
return null;
}
final item = result.first;
dynamic value = item['value'];
if (enableEncryption) {
final decryptedValue = _decrypt(value);
value = jsonDecode(decryptedValue);
}
return CacheItem<dynamic>(
value: value,
expiry: item['expiry'] != null
? DateTime.fromMillisecondsSinceEpoch(item['expiry'] as int)
: null,
);
}