Page 1 of 1
MX-Tweak Feature Request: User cache in RAM
Posted: Sat Aug 29, 2020 12:56 am
by agnivo007
Users may find this particularly useful for installations on SSD/SD/Flash media to prevent excessive writes, especially when web browsers are used.
Also, it helps keep /home directory slim, better app response times and aids housekeeping.
[X]Checkbox : User cache in RAM (warning: contents cleared on every boot)
Creates /home/user/.xsessionrc file as:
Code: Select all
export XDG_CACHE_HOME=/dev/shm/$(whoami)
mkdir -p /dev/shm/$(whoami)
chmod 700 /dev/shm/$(whoami)
export XDG_RUNTIME_DIR=$XDG_CACHE_HOME
Re: MX-Tweak Feature Request: User cache in RAM
Posted: Sat Aug 29, 2020 7:34 am
by dolphin_oracle
one directory on the file system does that replace?
Re: MX-Tweak Feature Request: User cache in RAM
Posted: Sat Aug 29, 2020 7:41 am
by fehlix
according to XDG Base Directory Specification
$XDG_CACHE_HOME defines the base directory relative to which user specific non-essential data files should be stored. If $XDG_CACHE_HOME is either not set or empty, a default equal to $HOME/.cache should be used.
The question remains whether an app do respect this specification.
Re: MX-Tweak Feature Request: User cache in RAM
Posted: Sat Aug 29, 2020 7:47 am
by fehlix
agnivo007 wrote: Sat Aug 29, 2020 12:56 am
Users may find this particularly useful for installations on SSD/SD/Flash media to prevent excessive writes, especially when web browsers are used.
Also, it helps keep /home directory slim, better app response times and aids housekeeping.
[X]Checkbox : User cache in RAM (warning: contents cleared on every boot)
Creates /home/user/.xsessionrc file as:
Code: Select all
export XDG_CACHE_HOME=/dev/shm/$(whoami)
mkdir -p /dev/shm/$(whoami)
chmod 700 /dev/shm/$(whoami)
export XDG_RUNTIME_DIR=$XDG_CACHE_HOME
I'm not sure about this one:
Code: Select all
export XDG_RUNTIME_DIR=$XDG_CACHE_HOME
b/c XDG_RUNTIME_DIR is already set to /run/user/$UID
Re: MX-Tweak Feature Request: User cache in RAM
Posted: Sat Aug 29, 2020 10:23 am
by dolphin_oracle
there are some items in .cache that persist across reboots, including the fontcache, and even more if a user uses flatpaks.
in particular the fontcache would need rebuilt every boot if the cache were moved to ram, or things will not look correctly.
Re: MX-Tweak Feature Request: User cache in RAM
Posted: Sat Aug 29, 2020 12:07 pm
by agnivo007
I have been using the above code for weeks now and zero problems on Firefox, Opera and Brave browsers which thrash disk cache a lot.
And yes, logged-in sessions seems to persist too after reboot, the apps above seem to honor the XDG envs.
Deleted /home/user/.cache after putting in .xsessionrc and it works as no files are created anymore in that folder but in /dev/shm/user/

Re: MX-Tweak Feature Request: User cache in RAM
Posted: Sat Aug 29, 2020 12:10 pm
by agnivo007
fehlix wrote: Sat Aug 29, 2020 7:47 am
b/c XDG_RUNTIME_DIR is already set to /run/user/$UID
What I posted was not distro specific, so if that is the case with MX, it can be omitted...
Re: MX-Tweak Feature Request: User cache in RAM
Posted: Sat Aug 29, 2020 12:50 pm
by SwampRabbit
agnivo007 wrote: Sat Aug 29, 2020 12:07 pm
IDeleted /home/user/.cache after putting in .xsessionrc and it works as no files are created anymore in that folder but in /dev/shm/user/
I think this is a cool suggestion with possibilities.
Out of curiosity, how long have you gone without rebooting?
Have you checked a few times to see how large /dev/shm/user/ is getting after a day or two of use?
Asking because I think this option has uses, but it could be bad for many users with limited RAM, and users who don't pay attention to warnings like what you smartly included lol.
I think saving flash media (SD cards/USBs, etc) from getting thrashed would be good, SSDs... maybe older ones, but the newer ones, they can take a huge beating.
Re: MX-Tweak Feature Request: User cache in RAM
Posted: Sat Aug 29, 2020 12:54 pm
by fehlix
I'd probably go in the direction and set for those apps, cache usage:
E.g for firefox I do allow only ram-cache, nothing written into the cache folder:
ff_about-cache.png
for those chromium based, apps I'd also use some flags like
Code: Select all
--disk-cache-dir=/run/shm/vivaldi
--disk-cache-dir=/run/shm/brave
--disk-cache-dir=/run/shm/chromium
etc.
This would avoid any other stuff like fontconfig cache or thumbnails needs to be rebuild after every reboot,
or in case of fonconfig probably not available. So some fonts might get not displayed properly.