Inappropriate Setting of XDG_CACHE_HOME May Slow Down Plasma Startup

KDE Plasma had been taking unbearably long to startup since an update one or two months ago for me. I thought it was caused by a bug of Qt but things turned out that this was not the fix to my problem.

Then I suddenly noticed that actually only the initial start after a boot would be slow, subsequent ones are way faster. So it must be a caching issue. I have mounted my /tmp in memory and moved a bunch of hot files into it and all of them will be lost after reboot. This is a common approach to make SSDs live longer and improve performance that could be found in many tutorials.

But some caches are designed to be reused after reboot. By default, they are often located in ~/.cache or /var/cache and you have to be really careful when relocating them, e.g. XDG_CACHE_HOME. Many Qt compilation caches are stored in this path and if you erase them after shutdown, it will have to re-compile them again on each boot.

Hence an easy fix here could be:

mkdir -p /tmp/xdg_cache
if [ -d $HOME/.cache/xdg_cache ]; then
    rsync -a $HOME/.cache/xdg_cache/ /tmp/xdg_cache
if [ -d /tmp/xdg_cache ]; then
    rsync --exclude='google-chrome' --exclude='pacaur' -a /tmp/xdg_cache/ $HOME/.cache/xdg_cache

I ignored the caches of Chrome and Pacaur as they are not needed after reboot and usually quite large.