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 {
final p = await prefs;
final result = <String, CacheItem<dynamic>>{};
for (final key in keys) {
final prefKey = _getKey(key);
if (p.containsKey(prefKey)) {
final String? jsonString = p.getString(prefKey);
if (jsonString == null) continue;
Map<String, dynamic> jsonMap;
if (enableEncryption) {
final decryptedValue = _decrypt(jsonString);
jsonMap = jsonDecode(decryptedValue);
} else {
jsonMap = jsonDecode(jsonString);
}
result[key] = CacheItem<dynamic>(
value: jsonMap['value'],
expiry: jsonMap['expiry'] != null
? DateTime.fromMillisecondsSinceEpoch(jsonMap['expiry'] as int)
: null,
);
}
}
return result;
}