-
Notifications
You must be signed in to change notification settings - Fork 9
Careful considerations concerning clearing cache
The script modifies some script files of Firefox within the omni.ja
and browser/omni.ja
archives.
Firefox uses a script cache for these files, the so-called “startup cache”.
Every Firefox profile has its own startup cache.
If the startup cache is never cleared, the changes that the script makes will never be applied.
The detailed Super User answer talks about the different ways that the startup cache can be cleared:
- If Firefox starts in an environment with the
MOZ_PURGE_CACHES
env flag set (to1
), then the cache will be cleared. - If Firefox starts with the
-purgecaches
option, the cache will be cleared. - If Firefox starts while an (empty) file called
.purgecaches
is in the…/browser
directory, the cache belonging to…/browser/omni.ja
will be cleared. If Firefox starts while such a file in the parent directory, the cache belonging to the parentomni.ja
will be cleared. - The startup cache can be cleared manually by deleting various
/home/⟨user⟩/.cache/mozilla/firefox/⟨profileID⟩.⟨profileType⟩/startupCache
directories.
The first three approaches are all equivalent, but which approach is better than another depends on how Firefox is executed, e.g. from terminal vs. from clicking an icon.
The current version of the script automatically attempts approaches 3 and 4.
If any one approach fails, the other still serves as a fallback.
If, say, the user’s .cache
directory could not be found, then, at least, Firefox clears the cache at the next startup, but maybe not on subsequent runs.
If both approaches fail, you’ll need to use one of the above approaches manually.
What the script attempts to do sounds complicated, but it’s difficult to find the optimal approach here. When reporting bugs, please be aware of this cache mechanism:
- Check if the startup cache in
~/.cache/mozilla/firefox/⟨yourProfile⟩
is being cleared when the script is finished. There should no longer be a directory calledstartupCache
. - Check if a file called
.purgecaches
is created by the script in thebrowser
directory of your Firefox install path.
In the past, the script did none of these approaches.
Instead, the user was told to add the -purgecaches
option manually in their .desktop
file of Firefox or run firefox -purgecaches
in the terminal.
But Issue #1 revealed that the .desktop
file possibly needed to be edited again after every update.
Since then, approach 3 is used by the script: a .purgecaches
file is created in the …/browser
directory.
Finding the .desktop
file automatically is difficult to pull off in a platform-independent and fast manner.
But then, Issue #8 revealed two things:
- While fixing Issue #1, I was concerned with what would happen, if the script would be executed twice in a row. In order to avoid changing the script files twice, and possibly replacing the wrong things, I checked if the
.purgecaches
file was still there. Firefox is supposed to remove this file as it clears the cache. If the file is still there, it would mean that the replacement likely has already occurred, and Firefox needed to be started before the script could be run again. This was flawed for two reasons:- Not every Firefox installation has write access to the
…/browser
directory, so the.purgecaches
file is not always automatically removed. - The existence of the
.purgecaches
file doesn’t actually tell you anything about which changes have been made.
- Not every Firefox installation has write access to the
- If the
.purgecaches
file is there, Firefox only clears the startup cache of the currently used profile on startup. It doesn’t necessarily clear other profiles’ caches on subsequent runs, especially if the.purgecaches
file is removed by Firefox.
Since then, the script no longer checks for .purgecaches
, and approach 4 is used in addition: the script directly deletes the startup cache of all profiles belonging to the current user.