Prevent SSD wear by using a RAM disk for cache
Jan 04, '11 07:30:00AM
Contributed by: QuickSander
Installing a new OCZ Vertex II SSD in an old 2006 iMac really speeds things up (and is documented in photos here).
However, I was searching for ways to limit the wear of my SSD (since each cell has a limited lifetime with regards to writes). One solution was to store the Safari cache on a RAM drive which will only be written to disk at logout.
Several hints on this site describe a way to store Safari cache on a RAM drive. However, none seemed to work for me because:
- Some RAMdrive creators were not available for download anymore (EsperanceDV).
- Other scripts did not provide a way to store the cache to disk at logout.
Therefore, I created this Mac OSX application (which is actually a simple Bash script), which you can place in your login items which will create a RAM drive and store/restore Safari cache on login/logout.
To get it running:
Actually you can store anything to the RAMdisk and the app will restore it on login, but let's use the Safari cache as an example.
- Install an up to date version of rsync, with Mac OS X and HFS+ enhancements for rsync.
- Download and unzip my app from the above link.
- In Finder do a 'Show Package Contents' of the just downloaded app and edit the file: Contents/MacOS/cache2RAM.sh
- Edit the lines below #Settings to your wishes (or anything else you want to change). You can change RAM disk size, name and the backup directory path here.
- Save the file and drag the Cache2RAM.app bundle to your login items (System Preferences » Accounts.
- Logout and login again.
Open Terminal and type:
When you start up Safari it will create the cache on the RAM disk and at logout Cache2RAM.app will store it for you on disk (so it can be restored later on automatically). Now SSD cache writes are limited to logout only.
rm -rf ~/Library/Caches/com.apple.Safari; ln -s /Volumes/RAMDisk/[username]/SafariCache ~/Library/Caches/com.apple.Safari
[crarko adds: I haven't tested this one. I've mirrored the application here.
I made some corrections based on the comments.]
Mac OS X Hints