removeNotMatching method
Remove any cache entry that is not relevant given the remaining taskNames and keys.
Implementation
Future<void> removeNotMatching(
Set<String> taskNames,
Set<String> keys,
) async {
final encodedKeys = keys.map(_encodeKey).toSet();
var removedCount = 0;
final oldTasks = Directory(_tasksDir).list();
await for (final oldTask in oldTasks) {
if (!taskNames.contains(path.basename(oldTask.path))) {
logger.fine(
() =>
"Removing task '${oldTask.path}' directory as task is not part of the build",
);
await oldTask.delete(recursive: true);
removedCount++;
}
}
final oldEncodedKeys = Directory(_hashesDir).list();
await for (final oldEncodedKey in oldEncodedKeys) {
if (!encodedKeys.contains(path.basename(oldEncodedKey.path))) {
logger.fine(
() =>
"Removing key '${oldEncodedKey.path}' as key is not part of the build",
);
await oldEncodedKey.delete(recursive: true);
removedCount++;
}
}
logger.fine(
() => 'Removed $removedCount cache entries that are any longer relevant',
);
}