How Does Your Caching Work?

This post is the ninth in a series called “Pagely Answers“, which seeks to provide in-depth answers to questions that are hard to handle with a simple FAQ.

We cache HTML content wherever possible because it’s an order of magnitude fast (500ms vs 10ms) and a couple orders of magnitude more scalable (50 concurrent users verus 100k). We only cache GET requests. We don’t cache any requests that set a cookie. We know about standard WordPress cookies and don’t cache them if you are logged in, or have a WooCommerce item in your cart as an example.

Caching works by building a cache key, every request that matches that key gets the same page, so if you are using information not in that key to change your output then it will not work properly. On VPS plans and above we can create custom cache keys and rules for you. The cache key is HTTP or HTTPS, domain, request URI, and normalized user agent (mobile, desktop, tablet, or RSS bot).

As an example of how we don’t cache requests that set a cookie:

We remove utm_* attributes from the query string when building cache keys. So running an AdWords campaign doesn’t hurt performance.
A user comes to your website, based on the query string ?utm_source=campaign1 or ?utm_source=campaign2 and you output a specific message. Because we remove utm_* from the query string it does’t work as expected. The first version that gets hit gets served to all users until the cache expires which is 30 minutes, and then the race to see what the new version is will happen again. A similar case would be looking at HTTP headers like referrer. So how do you solve this? Simply do your personalization on the client side using JavaScript, which also happens to be the most scalable solution. Also, ask us to configure a custom cache key for the site.

In terms of purging, when you update a page or post in WordPress, our plugin makes a request to the cache servers asking them to purge that page, the homepage of the site, and /feed/* as well. The way cache purging works is that there can be a delay on that purging.

NOTE: The key takeaway here and something that gets misunderstood a lot is that if the proper information isn’t present in the cache key (but is present somewhere else) then you will not get the results you want. You must put the proper information in the cache key to change your output. If you need custom cache keys and rules created then we are happy to do so for VPS and above.

1 Comment

  1. Thomas Zickell
    Thomas Zickell

    Great info & I love my Pagely VPS Awesome to have an enterprise network combined with excellent support, cutting-edge technology Redis + Nginx & now HHVM!

    HHVM does not use traditional caching and is absurdly fast.

    Reply