Skip to content

Why is there a .cache folder and can I point it to /tmp?

The title

101 points41 comments
Open on Reddit
About this post
Posted
Archived
Score
101 · 92% up
Kind
Text
ID
ozitlp

47 comments

can I point it to /tmp?

Yes.

SHOULD I point it to /tmp?

Only if you thoroughly enjoy loading screens and weird behavior.

225 points

Oooh, new project: symlink .cache to /tmp, forget all tf about it, reach mental brink trying to figure out why the hell all this odd crap is goin wrong.

50 points
unknown author

Deleted before we saved it.

-2 points
unknown author1 hidden

Deleted before we saved it.

-2 points
unknown author

Deleted before we saved it.

3 points

Because things need to store cache somewhere, and sure, you can, if you don't mind it being wiped when you shut down the machine.

72 points

Pop quiz hotshot. Your computer is running at 3.2 GHz and the minute you shut it down, you lose all your user cache. What do you do? What do you do?

2 points

https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html

XDG Base Directory Specification
[...]
There is a single base directory relative to which user-specific non-essential (cached) data should be written. This directory is defined by the environment variable $XDG_CACHE_HOME.
[...]
If $XDG_CACHE_HOME is either not set or empty, a default equal to $HOME/.cache should be used.

https://wiki.debian.org/XDGBaseDirectorySpecification

The XDG Base Directory Specification (XDGBDS) defines four categories of so called DotFiles and the corresponding directories in a user's home directory that should be used for those. The categories are cache, configuration, data and runtime files. There is not yet a separate categorie for "state" files although such a categorie has been requested several times

The state category was added in the latest version of the standard, which is 0.8.

. DATA CONFIG STATE CACHE RUNTIME
sync across machines? yes? yes no no no
manage in VCS (Git/SVN)? no yes no no no
should be backed up? yes yes yes no no
can live in tmpfs? no no no yes yes?
contains much data? yes no no yes no
50 points
unknown author2 hidden

Good to know!

6 points

You mention down-thread that specific programs are badly behaved - setting the environment variable only when you run the misbehaving program, and leaving the cache where it is, might solve your problem without broader impact.

7 points

Did a columns get misplaced, DATA is on the topics. All row titles should be +1. Moving CACHE to no for 'backup' and yes for 'can live in tmpfs'.

Incidentally I've been having a tmpfs fstab entry for $XDG_CACHE_HOME for many years and never had any issues. Good to know it actually matches the specification :) up-voting for references!

1 points

There is a non-breaking space on the first column. Looks like the new reddit doesn't like it, but it's working fine on old reddit. The entire markdown parsing is a mess on both reddit versions. Really annoying. Let me fix it real quick. The data however is copied correctly from the debian wiki page. If you don't agree with one of the values, that's fine though.

1 points

Its usually a bad idea to put the cache in /tmp. A smart application will understand /tmp is of limited size and avoid putting massive files in there.

44 points

I assume you want to point it at /tmp because you want to wipe your caches frequently.

But why?

A cache is a space-time tradeoff, as in it makes your programs faster at the cost of some disk space. So clearing your caches will just make your programs slower. And surely the amount of space it takes up isn't a problem.

This notion of clearing your caches as regular system maintenance is totally wrong, and I hate that it has spread so much.

The only actual reasons you would need to clear your caches are:

  • You are running out of disk space. Clearing your cache is a temporary solution until you can either get more storage or clean up your drive in some other way.

  • Your program is misbehaving. A poorly designed program can be incompatible with a cache created by an older version, and this incompatibility could manifest in weird ways. Or you could mess around with some configuration that invalidates the cache in a way that requires manual intervention. Both of these cases are highly unlikely with well designed software.

  • Privacy. If a third party will have temporary read access to your drive, you may want to clear your caches before you grant that permission. Note that this is a one-off case. If that third party will have persistent access, then your privacy is compromised regardless of caching, so you might as well keep the caches around.

31 points
unknown author9 hidden

Two programs are throwing junk into ~/.cache and never deleting it so its 16+GB for no reason. One generates random folder names so I can't just link the folder it uses

9 points

The .cache dir in your home stores cache from your apps. If u delete and send all to /temp everytime u reboot that will be wiped, you must dont do that.

6 points

If you mean .cache in your user directory, that is meant to store GPU cache, the songs you listen in Spotify, and other similar stuff.

/tmp is emptied every time you reboot, so it wouldn't be wise to have your cache files there.

5 points

No, that’s generally a bad idea. It contains, as the name indicates, cached data that applications use between runs.

/tmp is usually mounted onto memory, do won’t survive reboots. You’ll be eating up memory and everything we’ll be slower after every reboot.

If you want to move it, read the XDG basedir spec, the cache location is controlled via an environment variable.

5 points

It all depends on many factors. Your storage, your media containing your home directory, the applications you use etc. Etc.
I have a Void installation on an 8GB usb storage, I use it whenever im not on my own pc (a slow linux is better than windows) on that one, .cache is defined as tmpfs in my fstab. Meaning that it is mounted on RAM. (The same as pointing it to tmp)
On my gentoo installation, I point it to RAM when I want to compile something heavy, then reduce my compilation tasks by one (I dedicate two GB to .cache) this way emerge can access my source files on the fly and makes compilation at least 30% faster compared to having one more compiler task at a time. (The same with compiling AUR packages on ARCH)
Cache is usually meant to be used for temporary files, download parts, somewhere to store data that will be discarded/not needed soon. SO, basically losing .cache folder is totally fine and all your apps would work perfectly fine. But there are softwares (usually ported from windows) that treat .cache folder like Users\AppData folder of windows and store their data there, like a good amount of ported games store their save files there. That is when mounting your .cache on RAM would be a disaster.

A rule of thumb: rename your .cache to .cacheOLD and restart, try all your apps and see if any of them misbehave. if all of them are working fine, be my guest, make a symbolic link and create a new .cache folder that resides in tmp (or define it as tmpfs in fstab, if you have enough ram)
If you noticed any misbehaviour, just remove the new .cache folder, and rename .cacheOLD back to .cache , everything will be back to the way it was before

3 points
unknown author

If cache becomes a problem again I'll try renaming and doing what you suggested

1 points
unknown author

Deleted before we saved it.

1 points

I've pointed it to /tmp for years as per the tmpfs archwiki.

/etc/fstab e.g. tmpfs /tmp tmpfs rw,nodev,nosuid,size=2G 0 0

Works for me, I have 24GB RAM, never see more than 17GB RAM used. I have the tmpfs set to 10GB.

-10 points
unknown author5 hidden

How do you point it? ln -s /tmp $HOME/.cache?

-5 points

I like how you ignored all of the advice here to reply to the one person telling you how to do it - and got downvoted do that advice. This oughta go well.

11 points

Keyboard shortcuts

Move and act

jork
Next / previous post or comment
Enteroro
Open the post
f
Open the media viewer
s
Save
h
Hide (the toast has Undo)
Tab
Right after an action: the toast's Undo
x
Collapse the comment
v
Next layout: cards, compact, grid

Go to

/
Search
gthenh
Home
gthena
All
gthens
Subreddits
gthenl
Library
?
This list
Esc
Close a menu or this list

In the viewer

←or→
Previous / next file
↑or↓
Previous / next post
korj
Previous / next post
Space
Play / pause
m
Mute
z
Zoom
s
Save
o
Open the post (on its own page: back to it)
Esc
Close

Keys do nothing while you type in a box.