Refactored the storage of a temporary version of the local cache.

The two methods ``with_local_cache`` and ``bypass_local_cache`` basically do the same thing and save a temporary version of the local cache.

I've refactored this into its own method so that the code can be reused.