Friday, September 02, 2011

Ubuntu: Run chrome with cache in a ramdisk

This script will create a ramdisk, mount it and run chrome using it as it's cache location. Depnding on how much memory you have in your system, you can adjust the size of the ramdisk by modifying the CACHE_MB variable (number of MB you want to allocate). You can modify the icon that launches chrome to use this script, just place it somewhere in you home directory.
While not secure, I recommend adding /bin/mount and /bin/unmount to your sudoers so that you don't have to enter a password every time you run it.


#!/bin/bash
#Anthony Camilo 09/02/2011
#
# config
CACHE_DIR=/tmp/chromecache
CACHE_MB=128

#do not modify below
CACHE_SIZE=$(($CACHE_MB * 1024 - 1))
if [ ! -d  $CACHE_DIR ]; then
    mkdir -p $CACHE_DIR
else
    find $CACHE_DIR -mmin +480 -delete
    mkdir -p $CACHE_DIR
fi
sudo mount -t tmpfs -o size=$CACHE_MB'M' tmpfs $CACHE_DIR
/opt/google/chrome/google-chrome $1 --disk-cache-dir="$CACHE_DIR" --disk-cache-size=$CACHE_SIZE
sleep 10
sudo umount -fl $CACHE_DIR

No comments:

Post a Comment