I decided to revisit my idea I had a few months ago where I would cut down on the cache files being created on my SSD and I think I found a new solution.
Basically I set up a RAM Disk and redirect certain cache folders from my ~/Library/Cache/ folder to equivalent folders on the RAM Disk. Mainly cache folders from my Chrome, Firefox and Safari browsers, especially Chrome which can get pretty big if left to go for a few days. (When I deleted it tonight, it was at 500MB.)
First I create a RAM Disk and create the folders for the Cache I need:
Code:
diskutil erasevolume HFS+ "RamDisk" `hdiutil attach -nomount ram://2000000`
mkdir /Volumes/RamDisk/Google
mkdir /Volumes/RamDisk/Firefox
mkdir /Volumes/RamDisk/com.apple.iTunes
mkdir /Volumes/RamDisk/com.apple.mail
mkdir /Volumes/RamDisk/com.apple.iCal
mkdir /Volumes/RamDisk/com.apple.Safari
I placed the above code in an Automator application under a "Run Shell Script" module and threw it in my User Startup Items list, but you can place it in an actual Shell script or an AppleScript if you want. I did it my way for simplicity's sake. I chose 2000000 for the size which makes it 1GB. You can use 1000000 if you want 512MB or whatever you want. It doesn't seem to actually use the RAM until the files are created so you don't have to worry. You could probably get away with 256MB if you wanted to if you happen to have limited RAM.
One folder you cannot create is Finder, and any cache folders for apps that may run before the script has a chance to run itself. So just stick to browsers and apps with a front end GUI that are launched by the user and not ones that are set to open at login.
Next I have to create the Symbolic Links in the Cache folder in place of the original folders using this format in the Terminal:
Code:
ln -s /Volumes/ramdisk/CACHE_FOLDER_NAME /Users/YOUR_USERNAME/Library/Caches
ln -s FOLDER_TO_LINK_TO LOCATION_FOR_SYMLINK
Where CACHE_FOLDER_NAME is Google, Firefox, com.apple.Safari or whatever the folder name you are replacing is.
As a safety precaution I lock the symlinks in the Finder to prevent them being accidentally deleted, because if they do get deleted, the caches will be reverted to forming on the SSD instead, which is what we're trying to avoid.
The only problem I'm having is hiding the RAM Disk volume on the desktop. It doesn't seem to work if I name it with a period, and using SetFile (A Developer Tool) on it doesn't seem to work either. So I'll live with it until I figure it out.
Why do this? Because it saves on SSD file writes and being an SSD, cache files are not needed. Cache is created to save time creating files on the HDD, but since the speed of a SSD is so much higher, cache makes no speed difference at all. So it's no slower to load from the cache as it is to create the files from scratch.
What's a RAM Disk? A RAM Disk is a disk that is created in RAM. You can save and load files from it, and it's very fast. An added bonus is that it gets destroyed at shut down and does not get written to the disk so you're saving on disk writes and reads.
Is it safe? As far as I know. I'm still doing tests, but it seems to be working great so far. Should save me a buttload of file writes and a half a gig or so of used space on my SSD.
To revert to the old ways, simply delete the SymLinks from the Cache folder and the script that creates the RAM Disk.
Also, this is for SSD's only. If you try this on a HDD boot drive, you will end up slowing your browser down instead.
Personally, I think Apple should make it so when the OS is running off SSD, it will not create cache. Or, will write that cache to a temporary RAM partition by default because there's no reason to create this stuff when running on a SSD.