keep file cache in $XDG_RUNTIME_DIR if available

Various Linux distributions have started moving user-specific "runtime"
data from /tmp to $XDG_RUNTIME_DIR (usually either /run/user/$USER or
/run/user/$UID, created by PAM at login time). This avoids several
security and/or privacy issues.
C compliance: initialize cache on failed exit