ENH: Use a temporary directory for caching

If prefix/LOCAL-REPO is not writable, we use a temporary directory for
caching.