There are tons of caching options for WordPress. Some of the popular plugins are Batcache, WP Super Cache, and W3 Total Cache. There are also services like Cloudflare and Fastly. On VIP Go, we use Varnish instances distributed across the world and route traffic to the nearest server over our Anycast network.

I’ve used almost everything on my blog over the years, but this time I wanted to keep it simple. Since I already use Nginx for SSL termination and proxying to a Docker container, I decided it would be easiest to cache the HTML there.

https://gist.github.com/joshbetz/63f08fc2f37e5e267d14f219d0f5b4ed

The configuration is pretty basic:

404s are cached for 30 seconds

301s (permanent redirects) are cached for 24 hours

Everything else is cached for 5 minutes

Pages are only cached if they’ve been accessed 3 times to avoid filling the cache unnecessarily. If you’re logged in or have a cookie that looks like it could be valid, you bypass the cache completely to avoid caching logged in data. One of my favorite parts is that I can serve stale content if there’s a server error. So if I break the Docker container, ideally people won’t notice 🙂

Ultimately this is easier to maintain than any of the other things I’ve tried and just as effective.

The full configuration is on Github.