cachestore: Use "write new, then rename" pattern, not "write in place"

This should fix race conditions when multiple processes attempt to
access the cache concurrently.

https://bugzilla.gnome.org/show_bug.cgi?id=724886