Ga naar de inhoud
Home » Cache directory niet in ${HOME} maar op lokaal filesysteem

Cache directory niet in ${HOME} maar op lokaal filesysteem

De cache directory ${HOME}/.cache kan-staan/staat-dus op het (auto-)mounted HOME filesysteem. Dit geeft een performance penalty. Je kunt dit zien als b.v. Chrome links-onder aangeeft Waiting for cache

Om er van af te komen moet je de cache op het lokale filesysteem zetten. Een goede plek zou ergens onder /tmp zijn. Nadat de cache fysiek onder /tmp staat moet je een link maken naar ${HOME}/.cache zodat de applicaties er geen last van hebben en tevens de cache kunnen gebruiken.

Het onderstaande scriptje controleert of dit het geval is, zo niet dan wordt een .cache onder /tmp aangemaakt.

HOMECACHEDIR=${HOME}/.cache 
TEMPCACHEDIR=/tmp/${LOGNAME}/.cache 
 
if [[ -L "${HOMECACHEDIR}" && -d "${TEMPCACHEDIR}" ]] ; then 
{ 
    echo "${HOMECACHEDIR} is a symlink to a directory to ${TEMPCACHEDIR}" 
} 
else 
{ 
    if [ -d "${HOMECACHEDIR}" ] ; then 
    { 
      # found the cache dir in the users homedir 
      if [ -d "${TEMPCACHEDIR}" ] ; then 
      { 
        # there is also a chacedir in the temp directory 
        echo "Found a .cache dir in ${HOME} and there is also a ${TEMPCACHEDIR} ... call your admin" 
      } 
      else 
      { 
        # there is no cachedir in the temp directory,  create it 
        mkdir -p "${TEMPCACHEDIR}" 
        # copy content of ${HOMECACHEDIR} into ${TEMPCACHEDIR} 
        cp -r "${HOMECACHEDIR}" "${TEMPCACHEDIR}" 
        # rename the old ${HOMECACHEDIR} into ${HOMECACHEDIR}ORG 
        mv "${HOMECACHEDIR}" "${HOMECACHEDIR}ORG" 
        # create the symlink  
        ln -s "${TEMPCACHEDIR}" "${HOMECACHEDIR}" 
      } 
      fi 
    } 
    else 
    { 
      echo "Found no .cache dir in ${HOME} ... call your admin" 
    } 
    fi 
} 
fi 
 
exit 0