How Nginx Caching Works

Oh Yes! How Nginx Caching Works

If you’ve done much research into different caching options, you’re likely to have come across Nginx FastCGI Caching. Not only is it the caching method we’ve chosen for the SpinupWP platform, but it’s been the subject of many of our other articles on caching, including Varnish vs Nginx FastCGI Cache: Which is Best for WordPress?, where various popular WordPress caching solutions were benchmarked. One thing is clear, Nginx FastCGI Caching is blazingly fast and relatively easy to configure. However, it does have its quirks, such as the difficulty in invalidating the cache.

All services on a Linux server are run as a specific system user. Nginx FastCGI Caching works best when both Nginx and PHP run as the same user. This means you can purge the cache files directly from PHP. Nginx will always create the cache files as the user it’s running under and it’s not possible to adjust this behavior. Similarly, all cached files are created with 0600 or 0700 permissions for files and folders respectively and this too cannot be adjusted. This means that when Nginx and PHP run as separate system users (which is often the case) you can no longer invalidate the cache from PHP. As you’re unable to customize the file permissions in Nginx, the solution is to have PHP create the cache files instead.

This brings us to WordPress caching plugins. You could install and configure one of the commonly used WordPress caching plugins, and this will go a long way in addressing any performance issues. However, if you look at the results from a previous set of benchmarks, you’ll see that Simple Cache (a WordPress caching plugin) was no match for the performance offered by Nginx FastCGI Caching.