make sure cached file is deleted if exception thrown during write