WpW: Friends Don’t Let Friends Microcache
Welcome to another installment of WordPress Wednesday!
Today’s Topic: Why You Shouldn’t Microcache
Disclaimer: The information contained in this post is accurate for LSCWP v1.6. If you are using a newer version of the plugin, some details may have changed. Please refer to our wiki for the latest!
We’ve discussed before why caching your WordPress site is a good idea, as well as the different options you have when it comes to caching. You’ll want to take a look at that series, if you missed it. One approach to page caching that we didn’t discuss is known as “microcaching.” Today we’re going to talk about microcaching and why you can do better for your WordPress blog.
What is microcaching?
Microcaching is a variation of full-page caching where a static copy of dynamically-generated content is stored extremely short-term, often for as little as one second!
There is only one scenario where microcaching should be considered: high-traffic sites that feature rapidly-changing public content. This includes sites that display real-time stock prices, breaking news, or sports scores.
Let’s look at an example:
A breaking news site gets 500 requests for one of its pages in 10 seconds. That is a lot of requests for WordPress to handle at one time. However, if the page is microcached for one second at a time, then only 1 request per second needs to get through to the backend. That’s 10 requests in a 10 second period. The other 490 requests can be served using slightly stale (1 second old) content from the cache. This extremely small TTL provides the illusion of dynamic content being served.
Why You Shouldn’t Microcache
Microcaching works, but only for a very specific site profile, like the one in our example. If your site has moderate traffic, content that changes less frequently than every few seconds, multiple views per page, or any personal content displaying at all, then you will be disappointed by microcaching.
Microcaching is overkill for moderate traffic.
Ideally, microcaching kicks in when server load is high, it does its thing until the volume of requests goes back to a reasonable level, and then it goes dormant until it’s needed again. If you don’t have a high-traffic site, constant microcaching could actually degrade system performance, as unneeded cache pages are repeatedly generated.
Microcaching wastes CPU for stable content.
If your content changes less frequently than every second (and, let’s face it, most content on the web changes much less frequently than every second) then microcaching is not for you. it is a waste of valuable system resources to continually re-cache pages that have not changed.
Microcaching can’t handle variable content.
Microcaching is not intelligent. It takes a snapshot of a page, and serves that same snapshot to everyone for the duration of its short life. There is no ability to cache personalized content, nor is there any allowance for edge side includes (ESI). On a WordPress site, by default, microcaching doesn’t work at all for logged-in users.
Microcaching makes no allowances for differing browser signatures or geographic location. Varying themes for mobile vs. desktop are ignored. Everyone gets the same content. No matter what.
This can lead to incorrect views being served to certain customers – a problem which is extremely difficult to troubleshoot, given how quickly the cache turns over.
Can LiteSpeed do better?
You bet we can! Let’s explore those microcaching limitations we mentioned, so you can see just how much better our solution can be.
LSCache can handle both moderate and high traffic
You might argue that there is a place for microcaching during a traffic spike, as we saw with our previous example of the breaking news site. That may be true, but what happens once the traffic spike is over? Microcaching doesn’t shine in that scenario, but LiteSpeed does. LSCache handles both the spike and the regular traffic beautifully.
Let’s say that we were to cache a page with a TTL of one week. No matter the level of traffic – one request per hour or 500 requests in a 10-second period – a single hit to the back-end during that entire week is all that would be necessary.
Microcaching is not acceptable as a permanent solution, because the load it would put on the server, re-caching every second, is excessive when the traffic doesn’t warrant it. LiteSpeed is designed for the long haul. It allows you to keep your site cached indefinitely for your regular visitors, and it effortlessly rises to the challenge of the occasional traffic spike.
LSCache doesn’t waste CPU for stable content
Devotees of microcaching would suggest that a TTL of one week, as in our previous example, would not be appropriate for a site with dynamic content. They would point to the risk of serving some very stale pages.
With LiteSpeed there is no risk of stale content. LSCache is different than most WordPress cache plugins. It features an intelligent tag-based system that purges the relevant pages from the cache automatically whenever the content changes. Leaving TTL at one week (or longer!) is not a problem with LSCache. If a new post is published, the related pages are immediately purged. If a new post is not published, then the pages continue to be served quickly from the cache until the TTL expires.
While a microcaching system might blindly re-cache content every second, LSCache is smart enough that you can set a long TTL and let the system determine when it needs to be re-cached. Don’t waste resources repeatedly re-caching content that hasn’t changed!
LSCache is smart about variable content
Like in microcaching, LSCache also takes a snapshot of a dynamically-generated page and serves that snapshot to site visitors. However, LSCache is smart enough to distinguish between public content (which is suitable for everyone) and private content (which is cached only for the particular user to whom it applies). LSCache has the ability to use ESI to serve private blocks of data within public pages, which means we can easily serve cached pages to logged-in users.
LiteSpeed Cache can distinguish between mobile and desktop views, browser signature, geographic location, and any number of other variations that may exist for a page.
When you employ microcaching, you are taking a one-size-fits-all approach to serving content, but one size definitely does not fit all! LiteSpeed Cache recognizes the diversity of your site’s visitors and responds appropriately with tailored content.
To Review: Why You Shouldn’t Microcache
Here are a few common scenarios that your cache solution may encounter. Can it handle them efficiently and correctly?
|Can your cache handle this?||LiteSpeed Cache||microcaching|
|Only public content on the page||✔||✔|
|Page has some private content (a personalized greeting, items in a shopping cart, list of the visitor’s recently-viewed pages, etc.)||✔||X|
|Page has different views for mobile and desktop||✔||X|
|Page content varies based on geographic location||✔||X|
|Page content varies for logged-in users||✔||X|
|Traffic is heavy||✔||✔|
|Traffic is moderate or light||✔||X|
|Content changes rapidly||✔||✔|
|Content changes rarely||✔||X|
Curious about all of this? If you want to go deeper into the details, check out our LSCaching 101 article – it explains everything about how our cache solution works.
Have some of your own ideas for future WordPress Wednesday topics? Leave us a comment!
Don’t forget to meet us back here next week for the next installment. In the meantime, here are a few other things you can do:
- Subscribe to the WordPress Wednesday RSS feed
- Download LiteSpeed Cache for WordPress plugin
- Learn more about the plugin on our website