Improve background cache logic. Fixes #411
Fix TypeError from race condition between resetting and using
transforms.