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 {
  final db = await database;
  final batch = db.batch();

  for (final entry in entries.entries) {
    final key = entry.key;
    final item = entry.value;
    dynamic value = item.value;

    if (enableEncryption) {
      value = _encrypt(jsonEncode(item.toJson()));
    }

    batch.insert(
      'cache',
      {
        'key': key,
        'value': value,
        'expiry': item.expiry?.millisecondsSinceEpoch,
      },
      conflictAlgorithm: ConflictAlgorithm.replace,
    );
  }

  await batch.commit(noResult: true);
}