Achieve atomic cache writes

`file_put_contents(...)` is not atomic and may cause issues on highly trafficked sites with the target files being read before they've been written completely and thus cached truncated.