Moving your browser cache to a ramdrive

Moving your browser cache to a ramdrive

So, memory is dirt cheap right now. Crazy considering the prices just 2 years ago. I started with 8GB in my machine, then upped it to 16GB.  The reality has been, sadly, that I haven’t really seen a speedup or perf improvement from that extra ram as I rarely seem to use over even 8gb of memory.  Think my max has been 12GB so far.  It’s not really wasted as Windows 7 Prefetch is populating it with programs in the background – but that’s not super- interesting now that I have an SSD drive.  However, I do want to save my SSD from lots of browser cache writes.  What if I told you that you could do that, speed up your browsing by about 20% AND keeping you more secure. How?  By moving the browsers cache to a ramdrive.

Benefits:

  • Speed – reports are anywhere from 20%-100% speedups
  • Privacy – When you shut down and the ramdrive goes away – your entire browsing cache and cookies are irrevocably erased unless you persist/restore it from a regular drive.  No tracking cookies or other nasty junk is left around.  No need to ‘safe delete’ files.
  • Security – I’ve also already seen where this method caught a pop-up virus because when I rebooted and the app tried to install itself during the bootup cycle, the payload that was in the cache was gone and I caught the installer’s error message.
  • As long as you’re mostly hibernating/waking and not rebooting, the cache stays active and in memory.
  • Free and automatic once set up with about 5 easy steps
  • Some browsers are building this method into the browser itself
  • If you want to persist the cache between reboots – you can with a simple checkbox select.

Downsides:

  • Unless you persist/restore the ramdrive to a regular drive, you have to rebuild the cache each time you reboot.  First browsing on a page requires the reload of all the data.
  • Could potentially slow down your entire system if you are running short of memory
  •  Requires an initial setup

So, how do you do it?  The detailed instructions are on the linked websites below, but I’ll summarize here in case those instructions go away.  This is for firefox, but works for all other browsers too.

  1. Download DataRam Ramdisk and install it.  Amazing little ramdrive program that works on x32 and x64 Windows systems all the way up and through Windows 7. Great GUI frontend, does everything you expect, super stable, restarts on boot automatically.
  2. Open the Ramdisk configuration utility after install:
    1. Select the Settings tab
      1. Set the size to anything from 500-1500mb
      2. Set the file system type to Fat32
      3. Check the Disk Label checkbox and make sure the drive name is ‘RAMDisk’
    2. Select the Load and Save tab (optional step if you want the cache to persist between boots)
      1. If you want the browser cache stored and reloaded when you shut down the machine, select ‘Save disk image on shutdown’ and ‘Load disk image on Startup’.  Make sure they point to the same image file.
      2. I don’t do either of these as I want my cache to go away.  Loading/Saving the state will also increase both your bootup and shutdown times.
  3. Open Firefox
    1. Type ‘about:config’ (no quotes) in the address bar
    2. Hit the ‘I’ll be careful’ button
    3. Right click – select New -> String
    4. Type ‘browser.cache.disk.parent_directory’ into the box and press OK
    5. Type the path of your BrowserCache directory using the drive letter of the Ramdrive i.e. ‘R:BrowserCache’
    6. Close all open Firefox tabs and windows
    7. Reopen Firefox, open any webpage, and see if there is a new directory called BrowserCache on your ramdrive.
  4. Fix the drive letter on reboot.  Ramdisk has an annoying feature.  On reboot, it’ll assign the Ramdrive whatever random drive letter is available.  Obviously, this breaks the cache directory assignment in Firefox.  You’d need to update Firefox each reboot to point to the right drive.  Totally unacceptable.  DataRam’s Ramdisk doesn’t allow you to specify the drive letter of the ramdisk.  Totally unacceptable.  But – you can get around this by having a script move the drive letter during bootup.
    1. Copy the below code, then use notepad or other text editor to save it in a file called C:RamdiskRename.bat
    2. Press Win + R (or find “Run” on start menu), a “Run” dialog will appear. Enter “gpedit.msc” and select the “gpedit” in Programs list.
    3. In the left pane, click “Local Computer Policy” -> “Windows Settings” -> “Scripts(Startup/Shutdown)”  then on the right side, click “Startup”
    4. In the pop-up dialog, On the “Scripts” tab, click “Add…” and add the “C:RamdiskRename.bat” to the list. Click “OK” to finish.

Thats it!  To test it, reboot your machine, and you should see the ramdisk always at R.  When you open the browser for the first time after a reboot, you should see the cache directory appear in that drive. Using the Chromium benchmarking tool, the original author found that page load times were reduced by around 20%.  Shutting down and restarting the browser is also a lot quicker.

Links:
http://downloadsquad.switched.com/2010/11/10/how-to-move-the-firefox-or-chrome-cache-to-a-ram-disk-and-speed/
http://www.zomeoff.com/fixing-the-drive-letter-for-your-ramdisk-a-simple-solution-to-dataram-ramdisk/

RamdiskRename.bat:
@echo off
:: Settings
SET _ramdisklabel=RAMDISK
SET _ramdiskletter=R:

:: Get ramdisk disk number in diskpart
echo list volume > %systemdrive%ListDrives.tmp
diskpart /s %systemdrive%ListDrives.tmp > %systemdrive%DriveList.tmp
FOR /F "tokens=2-4" %%a IN ('type %systemdrive%DriveList.tmp') DO @IF /I "%%c"=="%_ramdisklabel%" @set _ramdisknum=%%a

:: Create drive change script
echo. > %systemdrive%ChangeDrive.tmp
if DEFINED _ramdisknum (
echo select volume %_ramdisknum% >> %systemdrive%ChangeDrive.tmp
echo assign letter=%_ramdiskletter% >> %systemdrive%ChangeDrive.tmp
)

:: Run diskpart using the new script file
diskpart /s %systemdrive%ChangeDrive.tmp

:: Delete the script files
del /q /f %systemdrive%ListDrives.tmp
del /q /f %systemdrive%ChangeDrive.tmp
del /q /f %systemdrive%DriveList.tmp

exit /b 0

3 thoughts on “Moving your browser cache to a ramdrive

  1. Hi would you mind stating which blog platform you’re working with?
    I’m planning to start my own blog soon but I’m having a difficult time selecting between
    BlogEngine/Wordpress/B2evolution and Drupal. The reason I ask is because your design seems different then most blogs and I’m looking for something completely
    unique. P.S Apologies for getting off-topic but I had to ask!

  2. I’m using WordPress – but this theme is one that I modified and wrote up myself. I don’t even think of it as complete as I have a few problems with it and unfinished bits.

    I found WordPress to be the easiest to use so far, but I only do this in my spare time so I wouldn’t say I’m an expert. Let me know if that helps.

  3. Hey I know this is off topic but I was wondering if you knew of any widgets I could add to my
    blog that automatically tweet my newest twitter updates. I’ve been looking for a plug-in like
    this for quite some time and was hoping maybe you would have some experience with
    something like this. Please let me know if you run into anything.
    I truly enjoy reading your blog and I look forward to
    your new updates.

Leave a Reply to Melanie Cancel reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.