Eliminate cache writes to your SSD when using Opera

Unlike Mozilla or even earlier versions of Opera, the latter no longer allows the user to set cache parameters, even in ‘expert’ mode. If you have some ram to spare, however, you can create a ramdisk and have Opera write its cache to Ram instead your SSD. This cache will disappear when you turn off the machine, of course, meaning that pages may initially load a bit more slowly, but they will thereafter load more quickly because they’re being retrieved from RAM. For the perpetually paranoid, this is also a security enhancement, since nobody can snoop through your disk cache to see what you’ve been up to on the Internet.

First, we’ll want to create the ramdisk. You can do this from the command line with

mkfs -q /dev/ram1 65536

This creates a 65 MB ram disk, which seems to me about the right size. Alternately, you can add the following line to /etc/fstab to re-create the ramdisk every time at after a reboot:

tmpfs  /home/[name]/rdisk   tmpfs   nodev,nosuid,nodiratime,size=64M  0 0

Now, create a place in your home directory to put it and mount it there:

   mkdir ~/rdisk
   mount /dev/ram1 ~/rdisk

Next, you’ll need to create four directories there

   mkdir ~/rdisk/opera
   mkdir ~/rdisk/appcache
   mkdir ~/rdisk/shader
   mkdir ~/rdisk/GPU 

To trick Opera into writing to these, we’ll use symbolic links. There are four caches, located in ~/.config/opera and in ~/.cache. While Opera is not running, delete these caches and substitute links to the rdisk directories (substitute the name of your home directory for [name]):

   rm -r /home/[name]/.cache/opera 
   rm -r /home/[name]/.config/opera/Application\ Cache
   rm -r /home/[name]/.config/opera/GPUCache
   rm -r /home/[name]/.config/opera/ShaderCache
   ln -s /home/[name]/rdisk/opera/ /home/[name]/.cache/opera
   ln -s /home/[name]/rdisk/AppCache /home/[name]/.config/opera/Application\ Cache
   ln -s /home/[name]/rdisk/GPU /home/[name]/.config/opera/GPUCache
   ln -s /home/[name]/rdisk/Shader /home/[name]/.config/opera/ShaderCache

Since you probably won’t want to go through this procedure manually every time, a script can be made and made to execute from your login profile. Here’s the script that I made. I’m rather new to scripting, so there are doubtless improvements that can be made.

#! /bin/sh
# ~/oprstart.sh
#
if  $(mount | grep -c home/[name]/rdisk) != 1 ]
then
   mkfs -q /dev/ram1 65536
   test -d /home/[name]/rdisk
   if  $? != 0 ]  
   then 
      mkdir -p ~/rdisk 
      echo "mount point created"
   fi
   mount /dev/ram1 ~/rdisk
   echo "ramdisk created"
else 
   echo "ramdisk exists"
fi
test -d ~/rdisk/opera
if  $? != 0 ] 
then  
   mkdir ~/rdisk/opera
   mkdir ~/rdisk/appcache
   mkdir ~/rdisk/shader
   mkdir ~/rdisk/GPU 
   echo "directories created"
   exit 0
else
   echo "directories exist"
   exit 0
fi
exit 0

Paste the above text into a Leafpad or Gedit window and save it to your home directory as oprstart.sh. Make it executable with

chmod 755 ~/oprstart.sh

Now, use your text editor to modify your login profile. Add this line to the very bottom of the file and save

 ./opstart.sh

Something else you might also want to do is to limit the size of the cache to your ram disk’s capacity. This can be done by editing opera.desktop.

 su
   (enter password)
   leafpad (or gedit) /usr/share/applications/opera.desktop 
  

Find the line near the top that reads Exec=opera %U and change it to read

Exec=opera --disk-cache-size=60000000 %U 

Reboot and check that the ramdisk exists on ~/rdisk and check that the four directories have been create.

The use of symbolic links to move writes off your SSD isn’t limited to browser caches and ram disks. For instance, I’ve done something similar with the Google Earth cache. In this case, I’ve used a symbolic link to move it to an ordinary platter drive on my computer. Of course, the drive has to be mounted for this to work. In the case of GE, there’s more reason to want to save the cache from one session to another, which the ramdisk cannot do.