OSX‎ > ‎

RamDrive MacOSX and moving cache

RamDrive is an old trend to gain very high performance drive and use it for caching or doing a file processing in memory to do it in no time for developers, well here I found a script to create a ram drive in mac, then we will move caching for Safari, Chrome and itunes of Mac to increase it's performance to maximum, addion to that this will increase your SSD Drive life time because its time is based on number of writes.

The following script file is your way for better performance you can change it for anything you need, I actually was planning to create a free app for that, and I am working on it,
here is a snapshot of my Alpha Version of it:
(In progress ...)

here is the code:

CacheDisk4GB.sh

#!/bin/bash

# Size at the end is * 2048 where 2048 = 1 MB, so 1572864 = 768 MB,8388608 = 4GB and in this code I make it 4GB
#DISK=`/usr/bin/hdiutil attach -nobrowse -nomount ram://1572864`
DISK=`/usr/bin/hdiutil attach -nobrowse -nomount ram://8388608`

/usr/sbin/diskutil erasevolume HFS+ "RamDiskCache" $DISK

CACHEDIR="/Volumes/RamDiskCache/$USER"

# Chrome Cache
/bin/rm -rvf ~/Library/Caches/Google/Chrome/*
/bin/mkdir -pv $CACHEDIR/Google/Chrome/Default
/bin/ln -v -s $CACHEDIR/Google/Chrome/Default ~/Library/Caches/Google/Chrome/Default


# Chrome Cache
/bin/rm -rvf ~/Library/Application Support/Google/Chrome/*
/bin/mkdir -pv $CACHEDIR/Google/Chrome/Support/Default
/bin/ln -v -s $CACHEDIR/Google/Chrome/Support/Default ~/Library/Application Support/Google/Chrome/Default


# Chrome Canary Cache
/bin/rm -rvf ~/Library/Caches/Google/Chrome\ Canary/*
/bin/mkdir -pv $CACHEDIR/Google/Chrome\ Canary/Default
/bin/ln -v -s $CACHEDIR/Google/Chrome\ Canary/Default ~/Library/Caches/Google/Chrome\ Canary/Default

# Safari Cache
/bin/rm -rvf ~/Library/Caches/com.apple.Safari
/bin/mkdir -pv $CACHEDIR/Apple/Safari
/bin/ln -v -s $CACHEDIR/Apple/Safari ~/Library/Caches/com.apple.Safari

# iTunes Cache
/bin/rm -rvf ~/Library/Caches/com.apple.iTunes
/bin/mkdir -pv $CACHEDIR/Apple/iTunes
/bin/ln -v -s $CACHEDIR/Apple/iTunes ~/Library/Caches/com.apple.iTunes

# Spotify Cache
/bin/rm -rvf ~/Library/Caches/com.spotify.client
/bin/mkdir -pv $CACHEDIR/Spotify
/bin/ln -v -s $CACHEDIR/Spotify ~/Library/Caches/com.spotify.client

/usr/bin/chflags hidden /Volumes/RamDiskCache #Hide RamDisk directory


Comments