Categories
Linux WordPress

Cache up to 30 times faster

Is not bullshit I swear! Absolutely possible, but you need to be using a VPS or a dedicated server to do this.

This is really handy if you are not using a cache system such as APC or xcache, and you store your cached files in folders.

For this we will use TMPFS

Tmpfs is like a ramdisk, but different. Like a ramdisk, tmpfs can use your RAM, but it can also use your swap devices for storage. And while a traditional ramdisk is a block device and requires a mkfs command of some kind before you can actually use it, tmpfs is a filesystem, not a block device; you just mount it, and it’s there. All in all, this makes tmpfs the niftiest RAM-based filesystem I’ve had the opportunity to meet.

Example to use it in your WordPress:
(check the right paths)

Edit /etc/fstab/ and we add the file system

tmpfs /home/neo22s/wp-content/cache tmpfs defaults,size=2g,noexec,nosuid,uid=648,gid=648,mode=1755 0 0

Add a new line at /etc/rc.local in order to execute it on system start up:

ionice -c3 -n7 nice -n 19 rsync -ahv --stats --delete /_b/tmpfs/cache/ /home/neo22s/wp-content/cache/ 1>/dev/null

New crontab job (using crontab-e), to execute

*/5 * * * * /usr/bin/ionice -c3 -n7 /bin/nice -n 19 /usr/bin/rsync -ah --stats --delete /home/neo22s/wp-content/cache/ /_b/tmpfs/cache/ 1>/dev/null

Done!

Currently I’m not using this method since I have xcache that make my life easier working with w3 total cache plugin, great solution.

Of course you can use TMPFS for many other things, check askapache, where you can find loads of info and examples a great work.