Avoid erroneous 'Could not cancel' warning produced by cache tasks

When closing providers, we regularly see an erroneous warning related to a failure to cancel cache tasks.

This change applies some more defensive checks before attempting to cancel tasks, ensuring that the cancel operation is only attempted if the future has not completed.