Adding some race-condition protection to the cacheFile read/write