Manually solve ‘empty cache after crash’ problem in Firefox

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

What Others Are Saying

  1. Pradip Sep 7, 2011 at 11:02 AM

    Thank you very much for this article. I was looking for this information since several weeks. It becomes annoying when Firefox clears Cache automatically. Thanks again.

  2. Harry Nov 9, 2010 at 11:47 PM

    You know what….this is the coolest information I ever got. You bring me back my life.God bless U man

  3. gamer Jun 16, 2010 at 3:26 PM

    man u made my day…and saved me many hours of loading my favrite online games when ff crashed..ya know internet is very slooow in india.thanks a lot

  4. Pingback: Chennai Life – Ep.3 | A Little Lunacy! {v2}

  5. JB May 27, 2010 at 10:38 PM

    Nice find. How did you discover this? Is there any official documentation on this?

    • Abhishek May 27, 2010 at 11:09 PM

      I searched a lot and stumbled upon something on the web. I can’t quite recall where I saw it, though. :)

  6. Jarod Fontana Apr 10, 2010 at 3:27 PM

    When did you find getting that data? I tried to get some more details about it, but I wasn’t able to.

  7. Vinay Swastik Jan 20, 2010 at 8:15 PM

    This is really helpful. A very rare to find fix in Google.

    Thanks a million.

  8. Shishir Jul 2, 2009 at 8:33 PM

    Nice tut! Thanks! :)

    • Abhishek Jul 2, 2009 at 10:56 PM

      My pleasure! :)

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>