Moving Web Browser Cache
Why
Trust me. Well:
- If you have faster storage (but in limited quantities) than your home folder, this can speed up web browsing
- If you are backing up your home folder and want to backup your browser profiles (including settings, bookmarks, add-ons, etc), you really probably don't want to backup your browser cache as well. Backing up your browser cache is silly and will take up a lot of space and time.
How
Firefox
- Basically, you'll set a profile variable browser.cache.disk.parent_directory to the path on disk in which you want your cache stored.
- Then, you'll want to close Firefox
- Optionally, you can then move your browser cache from the old location:
~/.mozilla/firefox/<profilename>/cache2/
to the new path you specified. Otherwise, the next time you start Firefox, your cache will be empty (which may be a good thing if you want to start fresh). - Open Firefox and verify that it is writing to the new location
- Optionally: Clear any of the old data from your backups to free up space
If you run multiple Firefox browser profiles like I do, you'll need to make this variable change to each profile and give each of them separate paths (don't use the same path!). I use:
/scratch/jeremy/firefox/<profilename>/
My /scratch directory is located on a different zfs dataset (filesystem) that I use for any kind of variable data that I have no need to keep around. It is not backed up, but my profile settings (stored in ~/.mozilla/firefox/<profilename>/) will be.
See: http://kb.mozillazine.org/Browser.cache.disk.parent_directory for more details.
Google Chrome
Google Chrome operates a little differently. You can not set a variable in a config file to change the cache location. And if you are using multiple profiles, the way you do this will be different.
When using the default profile (without specifying the --user-data-dir command-line argument), Chrome writes its cache to:
~/.cache/google-chrome/Default
However, if you are running a different profile (using the --user-data-dir=/my/folder command-line argument), Chrome writes its cache to:
/my/folder/Default/Cache
This behavior is strange if you ask me, but that's what we have to work with for now. If you are only running one profile or when you are running the default profile you can simply do the following:
- Close the Chrome application
- Move the current cache folder to your preferred location:
mv ~/.cache/google-chrome /scratch/jeremy/cache/google-chrome
- Make a symlink to the new location:
ln -s /scratch/jeremy/cache/google-chrome ~/.cache/google-chrome
Now every time you open Chrome with the default profile it will follow the symlink and write the cache to your preferred location.
However, if you run multiple profiles it may be more consistent to create a shortcut or alias to open Chrome for each different profile using the --user-data-dir and --disk-cache-dir command-line arguments. For example my personal profile would be started with:
google-chrome --user-data-dir=/home/jeremy/.config/google-chrome-personal --disk-cache-dir=/scratch/jeremy/cache/google-chrome-personal
And my work profile would be:
google-chrome --user-data-dir=/home/jeremy/.config/google-chrome-work --disk-cache-dir=/scratch/jeremy/cache/google-chrome-work
Thanks for making that confusing, Google!