Save Your SSD! Move Caches To Ram Disk

Last year I have bought a MacBook Pro for a decent amount of money. It is a unibody "USB flashdrive" with some computational capabilities :)

One of the drawbacks of MBP (except it's ridiculously high price) is the fact that you cannot simply disassemble it and repair/change the broken piece of hardware.

The process will cost you another ridiculous sum of money.

One of the most questionable piece of hardware is a solid state drive (SSD).

I have little knowledge of SSD lifecycle, but having an inborn paranoia (all belarussian people have this little gift from the government) I stick to the fact that MBP owner should take special care about number of SSD read/write events (As SSD is told to have the limited r/w capabilities).

That's why I've decided to move all caches to the RAM disk (I have 16Gb of RAM, and use only 10Gb at most).

One more advantage of doing this is the fact that the RAM is still faster than SSD today.

How-To

I will assume that you have some kind of RAM disk control utility installed. I personally use iRamDisk.
Create two disks - one for Chrome and one for IDEA.

Chrome

There are several ways of moving caches to the RAM disk, but we will use a permanent way.

I have created a 512Mb disk called ChromeRAM and made it being created at login.

After the disk is created you should close the browser and issue the commands in terminal:

rm -rf ~/Library/Caches/Google/Chrome/Default  
ln -s /Volumes/ChromeRAM ~/Library/Caches/Google/Chrome/Default  

Yeah, there is no "magic configuration variable", but a simple cache directory.

The first command will kill all files in the Default cache directory.

The second one will create a symlink to your RAM disk (iRamDisk creates all disks mounted to the /Volumes directory - hence the /Volumes/ChromeRAM path).

And that's it!

IntelliJ IDEA

The process will be a little different.

I've created a 2Gb disk called IdeaRAM for IntelliJ cache. I have some large projects, so 2Gb is a reasonable size.
Thought, I would not recommend to make the disk size less than 1Gb.

After you have your disk created, close the IDEA and enter the following in the terminal:

sudo nano ~/Library/Preferences/IntelliJIdea13/idea.properties  

Things to note:

  1. You have to specify the root password to modify the idea.properties file.
  2. The number 13 is the IntelliJ version number.

You should change or add the next string in the opened file:
idea.system.path=/Volumes/IdeaRAM

After the restart IDEA will index all the files in your project into the new directory. If you want to speed up the process a little, you can copy the existing cache from ~/Library/Caches/IntelliJIdeaXX folder to the RAM disk.

That's it!
You can bother no more - your cache will not tear down your SSD disk.

P.S. It can be a good idea to move the project build process to the RAM disk on your workstation if you do not have an SSD.

P.P.S. You can find info about IntelliJ IDEA default directories here.

Have a nice hacking!