call method

Future<void> call(
  1. FileCollection collection, {
  2. String key = '',
})

Cache all files and directories in the given collection.

Implementation

Future<void> call(FileCollection collection, {String key = ''}) async {
  logger.finest(() => 'Adding $collection with key="$key" to cache');
  Set<String> visitedEntities = {};
  await for (final entry in collection.resolve()) {
    if (visitedEntities.add(entry.path)) {
      await entry.use((file) => _cacheFile(file, key: key),
          (dir, children) => _cacheDir(dir, children, key: key));
    }
  }
  // visit entities that do not exist but may have existed before
  for (final file in collection.files.where(visitedEntities.add)) {
    await _removeEntity(File(file), key: key);
  }
  for (final dir in collection.directories
      .map((e) => e.path)
      .where(visitedEntities.add)) {
    await _removeEntity(Directory(dir), key: key);
  }
}