Cleanup ~purism/.cache

purism@pureos:~$ du -sh .cache
2.2G	.cache
purism@pureos:~$ du -s .cache/* | sort -n | tail -5
45692	.cache/geocode-glib
61132	.cache/gnome-software
81708	.cache/flatpak
281136	.cache/epiphany
1697192	.cache/mozilla
purism@pureos:~$ 

Is there a good way to clean this up by scripts periodically?

3 Likes

Check systemd timers see Systemd Timers for Scheduling Tasks - Fedora Magazine. The article has a good example.

1 Like

This article talks about how to schedule tasks, but not about how to clean old files below ~/.cache.

1 Like

Do you want to remove specific files or delete all folders under .cache ?

1 Like

I have had older cache areas of FF and removed the now unused ones:

purism@pureos:~$ ls -ltrd .cache/mozilla/firefox/*/cache2
drwx------ 4 purism purism  4096 Sep 29  2023 .cache/mozilla/firefox/r3ieje6m.default-esr/cache2
drwx------ 4 purism purism 36864 Sep 29  2023 .cache/mozilla/firefox/5zhqn2bz.default-esr/cache2
drwx------ 4 purism purism  4096 Sep 29  2023 .cache/mozilla/firefox/z22v0zdv.default-esr-1/cache2
drwx------ 4 purism purism  4096 Sep 29  2023 .cache/mozilla/firefox/a23d4cgf.default/cache2
drwx------ 4 purism purism  4096 Sep 30  2023 .cache/mozilla/firefox/ncntvv6t.default-esr-1/cache2
drwx------ 4 purism purism  4096 Oct  2  2023 .cache/mozilla/firefox/dz163yfz.default-esr/cache2
drwx------ 4 purism purism  4096 Apr 13 15:48 .cache/mozilla/firefox/mtcxch0t.default-esr/cache2
purism@pureos:~$ du -sh .cache/mozilla/firefox
1.7G	.cache/mozilla/firefox
purism@pureos:~$ rm -r .cache/mozilla/firefox/r3ieje6m.default-esr .cache/mozilla/firefox/5zhqn2bz.default-esr .cache/mozilla/firefox/z22v0zdv.default-esr-1 .cache/mozilla/firefox/a23d4cgf.default .cache/mozilla/firefox/ncntvv6t.default-esr-1 .cache/mozilla/firefox/dz163yfz.default-esr
purism@pureos:~$ du -sh .cache/mozilla/firefox
625M	.cache/mozilla/firefox

This freed up around 1 GByte. See also this article: How to clear cache in Mozilla Firefox | NordVPN chapter at the end about " How to clear Firefox cache from command line"

2 Likes

It is somewhat likely that there is no way to do this “officially”.

For example, it may or may not be a good idea just to go in and wildly rm a browser’s cache area. I mean a browser may handle the sudden disappearance of files gracefully, or it might not.

You are supposed to use the browser’s settings to clear cache and to limit the amount of disk space that the cache uses. I understand that that might not be compatible with doing it automatically or periodically in the way that you want.

Each application that uses cache would need to be considered separately e.g. what works for Firefox has no bearing on what works for Flatpak.

From the looks of it, you probably should go in and limit Firefox’s total cache usage. Looks as if the magic config parameters are browser.cache.disk.smart_size.enabled false and browser.cache.disk.capacity to a value in KB.

2 Likes

My values are (unchanged by me):

browser.cache.disk.smart_size.enabled: true
browser.cache.disk.capacity: 256000

purism@pureos:~$ du -sh .cache/mozilla/firefox/
638M	.cache/mozilla/firefox/

Why the cache with 638M exceeds the limit of 256M?

1 Like

Precisely because you don’t have the first setting that I mentioned set.

In this case “smart” means “controlled by the browser” rather than “controlled by you”. If you set that setting to false then it will mean that the limit is “dumb and absolutely fixed and inflexible” i.e. it will work as you want it. It will be a hard limit rather than a guideline.

1 Like

Sorry. I misread your post and changed it now to ‘false’; and it worked after FF restart:

purism@pureos:~$ du -sh .cache/mozilla/firefox/
637M	.cache/mozilla/firefox/

(FF restart)

purism@pureos:~$ du -sh .cache/mozilla/firefox/
284M	.cache/mozilla/firefox/
2 Likes