The Background:

Imagine that you have 400+ MB of Firefox’s cache brimming with websites that you visit regularly. If Windows crashes or the computer is not shut down properly while Firefox is still running, you WILL lose that cached data when you start Firefox again. Which basically means that every site you visit now will be downloaded all over again, since the cached files are no longer valid. If your computer has a nasty habit of crashing every now and then, or you run your computer in an environment devoid of a UPS and susceptible to frequent power outages, you will end up wasting a lot of bandwidth. And God help you if you are on a limited data transfer plan.

Why Does This Happen?

When you start Firefox it marks the cache as ‘dirty’ and when you close Firefox, the dirty bit is removed. So when Firefox is not properly closed, the cache remains tagged as ‘dirty’. Firefox checks the status of this bit on startup and when it sees the ‘dirty’ bit, it invalidates the entire cache and the cache is rebuilt from scratch, beginning from this session.

I have been plagued by this problem for a while now. Searching the Internet brought up vague results and recommendations to install an extension (which I haven’t been able to get installed till now). Then a few days ago I stumbled upon a post which actually explained the entire concept behind this behaviour. After reading this, I decided to write a tutorial on it.

Let’s Get Our Hands Dirty:

  • Frhed is a small, free and functional hex-editor that we will use for this tutorial. Download and install Frhed.
Download Frhed

Download Frhed

  • Now we need to locate the folder where Firefox has stored its cache. I am supposing that Windows is installed on the ‘C’ drive and that only 1 user-profile is being used in Firefox.
  • If you are using Windows XP, navigate to-

C:\Documents and Settings\<UserName>\Local Settings\Mozilla\Firefox\Profiles.

  • On Vista/Windows 7 machines, go to-

C:\Users\<UserName>\Local Settings\Mozilla\Firefox\Profiles.

  • Look for a folder that has the word ‘.default’ suffixed to it.
  • In that folder you will find a directory named ‘cache’. Open it.
  • Now look for a file named _CACHE_MAP_ in this folder.
Path to Firefox's cache

Path to Firefox's cache

  • Open this file with Frhed. It should look something like this:

_CACHE_MAP_ in Frhed

_CACHE_MAP_ in Frhed

  • Now in Frhed, go to the ‘Edit->Go To’ option. Type 15 and press Enter.
  • Why 15? Because the dirty bit is stored at that position in the _CACHE_MAP_ file.
  • If Firefox is currently running or was not closed properly, the value at this position will be 01.
The bits to be altered

The bits to be altered

  • As you can see in the image, the value at this position is 01, which indicates that the cache is currently marked as dirty. To change this, simply replace the 01 with 00 and save the file.
  • Now start Firefox and try opening any of the sites you regularly visit. They should open normally without the whole content being downloaded off the server, which is exactly what we wanted. :)
  • To make things even simpler, I’d suggest that you create a shortcut to the _CACHE_MAP_ file on your desktop so that you don’t have to go through the maze of folders to reach it again. ;)

So there you have it. By investing no more than a couple of minutes every time Firefox is not closed properly, you can save yourself a lot of bandwidth and time. :D