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 (!_isInitialized) await init();
final result = <String, CacheItem<dynamic>>{};
// Hive doesn't have a native getAll method, so we need to get each key individually
// but we can optimize by doing it in a single transaction
for (final key in keys) {
if (_box.containsKey(key)) {
final dynamic storedValue = _box.get(key);
if (storedValue == null) continue;
if (enableEncryption) {
final decryptedValue = _decrypt(storedValue);
result[key] = CacheItem.fromJson(jsonDecode(decryptedValue));
} else {
result[key] = storedValue as CacheItem<dynamic>;
}
}
}
return result;
}