A plain "file_put_contents" can cause havoc

This tries to make the saving of cached file atomic. It creates a new
tempfile, writes the content to it and than renames it to the
destination file.