getAll method
Retrieves multiple CacheItems associated with the given keys
.
Returns a map where the keys are the original keys and the values are the retrieved CacheItems. If a key is not found in the cache, it will not be included in the returned map.
Throws a CacheException if there is an error retrieving the data.
Implementation
@override
Future<Map<String, CacheItem<dynamic>>> getAll(List<String> keys) async {
if (keys.isEmpty) return {};
final db = await database;
final placeholders = List.filled(keys.length, '?').join(',');
final result = await db.query(
'cache',
where: 'key IN ($placeholders)',
whereArgs: keys,
);
final Map<String, CacheItem<dynamic>> cacheItems = {};
for (final row in result) {
final key = row['key'] as String;
final dynamic value = row['value'];
final int? expiryMillis = row['expiry'] as int?;
if (value == null) continue;
if (enableEncryption) {
final decryptedValue = _decrypt(value as String);
cacheItems[key] = CacheItem.fromJson(jsonDecode(decryptedValue));
} else {
cacheItems[key] = CacheItem<dynamic>(
value: value,
expiry: expiryMillis != null
? DateTime.fromMillisecondsSinceEpoch(expiryMillis)
: null,
);
}
}
return cacheItems;
}