putAll method

  1. @override
Future<void> putAll(
  1. Map<String, CacheItem> entries
)
override

Stores multiple values in the cache with the given keys.

Each 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> putAll(Map<String, CacheItem<dynamic>> entries) async {
  if (!_isInitialized) await init();

  final Map<String, dynamic> boxEntries = {};

  for (final entry in entries.entries) {
    if (enableEncryption) {
      boxEntries[entry.key] = _encrypt(jsonEncode(entry.value.toJson()));
    } else {
      boxEntries[entry.key] = entry.value;
    }
  }

  await _box.putAll(boxEntries);
}