A plugin to clear recalcitrant caches from inside WP Engine

We’re using WP Engine to host various clients, notably the Rolling Stones site, and we’ve been very pleased with both the service and the performance of their hosting platform. There’s always something though, isn’t there? I don’t think I’d really be happy if there wasn’t. In this case it’s the fact the Varnish caching layer that sits between the site and the visitors caches “non-200” responses for 24 hours. So what does all that mean? What’s the actual problem here?

What is Varnish caching? Well, “Varnish is a reverse proxy cache” …but what is a reverse proxy cache, you say? A reverse proxy cache sits between your website and the broader internet (where all the people and things that want to see your site are) and, according to a set of rules, caches responses somehow and serves them back super quick to the requests for URLs at your site. So your site generates a response, which might take some time due to database queries, requests to Twitter for the latest tweets, etc, etc, then the reverse proxy cache (Varnish, in this case) saves the response and returns it for requests without bothering the site to create the response from scratch… hey presto, much faster responses!

WP Engine have their Varnish configured to cache responses for 24 hours for non-200 responses. What are “non-200 responses”, you say? Every response to a request for a URL is assigned a response code, you can read them all over at the W3C (or you can read the much more amusing HTTP $tatu$ Rapper$). The main response codes we’re concerned with are 200 (“OK” – the request has succeeded) and 404 (“not found” – the requested resource has, errrr, not been found), there’s also various redirection codes 301 or 302.

The upshot of all this is that once a 404, 301 or 302 response is issued by a website on WP Engine, it remains in use for 24 hours unless something clears it deliberately. The major scenario of having a 404 response and then publishing something at that URL is covered, as you’d expect the cache gets automatically cleared, however there are the odd situations where I’ve needed to clear a cache for whatever reason (perhaps to replace a 404 with a redirect of some kind) and then I’ve been stuck staring at the 24 hour cached response and grinding my teeth.

Enter the WP Engine Cache Sniper plugin (actually I’ve called it “WPEngine Clear URL Cache”, which is quite a bit more boring). This plugin provides a simple “Clear URL Cache” link under the “Tools” menu in the admin area, here you can enter a URL and have the cache cleared on that URL. Problem solved.

Caveats: The plugin is specific to WP Engine, and won’t work on other services. If you try and install it on a non-WP Engine hosting service it will put a whinging notice throughout the admin, advising you to uninstall. If you try to use it on a non-WP Engine hosting service then it will kill a kitten, you may not see the kitten die and it may not be your kitten… but really, do you want that on your conscience? Oh and you might trigger an error in your site, who knows.

Join the Conversation

4 Comments

  1. This is awesome Simon! Very nice.

    Drop me an email with any other ideas of utility functions we should expose via end point URL/API that 3rd party devs could integrate into their scripts/plugins.

  2. Thanks Simon, this came in really handy, I was struggling with the same issue and looks like the only option with WPEngine is to open a support ticket which is not feasible since I’ve seen this often.

Leave a comment

Leave a Reply to IntricatePixels Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.