Speeding Up Nginx Caching With tempfs

screen-shot-2014-07-05-at-1.35.25-am

If you’ve done anything with optimizing the speed of websites, you know that caching is a must. It basically means you’re creating a page once, and then using it multiple times—as opposed to having to create it every time someone asks for it.

So caching is good, is what I’m saying.

Caching 2.0

There’s a caching superpower that you can employ that most people aren’t aware of: caching to memory instead of to disk.

Whether you’re using a caching plugin, or doing opcode caching, or using fast-cgi caching (or all three), you should be writing your cache files to a directory that lives in tempfs.

What’s tempfs

tempfs is a filesystem in memory. Most modern Linux distros have it on by default, actually:

  • In CentOS your default tempfs directory is /dev/shm

  • In Ubuntu your default tempfs directory is /var/run

So, whatever you’re using to create cache files, make use of your Linux distro’s built-in memory-based file system.

Related posts: