WP 6.2: Opt-In Change Boosts Caching Performance up to 70%

An abstract image of a caching system

Recent improvements to caching in WordPress core made by our Senior Engineer Jonny Harris can provide a serious boost to your website performance—but for now, they’re opt-in only. Here’s everything you need to know:

In this article, we’ll learn:

  • What an object cache is and how it speeds up your website
  • The work that’s been done to make object caching faster
  • Why this is an opt-in change rather than a standard
  • How you can advantage of the new changes on your own site

What is Object Caching and How Does it Work?

In WordPress, posts, images, users, and all other resources related to your website are stored in a central database. By default, any time a user loads a page, that database is queried (searched) and information such as title, content, and author are collected, ready to display in the browser.

In the early days of the internet, this worked fine, but with modern high-traffic and content-rich websites, completing so many database queries can cause a bottleneck, which slows down your site, and risks the database going down. 

This is where an object cache can be useful. Object caching is a way for WordPress to remember (or cache in computing terms) previously processed database lookups and keep them easy to access, so that only the first user to access a web page has to do a full database lookup— everyone else can use the cached version.

Object caching is pretty much crucial to running WordPress at scale, and it’s been a standard for enterprise websites since WordPress 1.5. Any hosting provider capable of running large-scale WordPress should have it enabled.  

Imagine your site is a kitchen. Your database is like a huge walk-in refrigerator. Finding the right ingredient and getting it out takes time, but it’s necessary to cook. Now imagine you already know that you know that today you’re making fish and chips. An object cache is like having a mini-fridge right on the counter, containing all the ingredients you need.

How Jonny Made Object Caching Even Faster

Previously, if you wanted to load a page with the previews for 10 different posts, the object cache would be called 10 times and the resources collected individually, one by one. This was faster than searching the database, but it still had a performance overhead as the cache is called with so many single requests.

Now, ten calls might not sound like a lot, but when you’re working at enterprise scale the number of these requests usually reaches the thousands. That’s a lot of unnecessary back and forth, and a lot of wasted compute power, which ultimately makes your site slower.

So, given that we know exactly which items we want from the cache, why don’t we pick it all up in one go? 

Well, this is where Jonny’s work comes into play. He spearheaded a function in WordPress core called wp_cache_get_multiple, where instead of ten single inputs, a list of 10 IDs would be called from the cache simultaneously.

Note: Some older plugins use a function called wp_cache_get_multi, this is different from wp_cache_get_multiple, and doesn’t have the performance benefits noted in this post.

This makes a huge difference. As we can see in the screenshot below, the homepage on this enterprise publishing site went from processing a massive 1478 individually processed requests and only 3 multigets, to only 287 gets and 103 multigets in WordPress 6.2.

We know that sounds a little bit techy— but this is a substantial drop in requests, which means a significant boost in speed—not only for your users, but for your team using the admin panel as well. As your server is having to process fewer calls to the cache things load quicker, giving your users information, ads, and products faster.

Why Doesn’t WP_Cache_Get_Multiple Work Automatically?

WordPress core is set up in a way that allows you to choose exactly how you implement your object cache. It’s completely customizable to your performance needs, and we can’t force developers down a certain path. WordPress as a platform must remain flexible.

So, when Jonny launched this functionality, he implemented it in WordPress core in all the places that made sense (and he’s still adding it in more areas as he uncovers new opportunities), but he also added what’s called a backward compatibility shim.

The shim detects if the wp_cache_get_mulitple function exists in your caching plugin. If it does, it uses it, if it doesn’t, it falls back to the default method of fetching each item in the object cache one item at a time.

This is a critical protocol to have in place, as WordPress can’t understand how customized object caches work, and trying to use wp_cache_get_multiple when your caching setup doesn’t account for it can cause your site to go down.

Opt-in to WP_Cache_Get_Multiple

This is an important point to make—the ‘opt-in’ part of this update does mean that your hosting provider or caching plugin needs to make a small code update on their end, but this is generally a simple task. 

When Jonny completed the work and merged it into WordPress core, he reached out to the most popular hosting providers and caching plugins to make them aware of the change—even producing the code that they would need on their end to implement it into their systems easily.

The result of this is that a number of performance-focused hosting solutions and plugins (like XWP partners Pantheon and WordPress VIP) have already adopted Jonny’s work into their systems, so their customers are already reaping the benefits of multi-object caching.

If you’re a developer and you want to learn how to implement this change. Stand by! We have a technical guide on the way that explains all the nuts and bolts of what makes Jonny’s work so important. 

Follow us on Linkedin and Twitter to make sure you don’t miss it!

WordPress Object Caching FAQs

Q: Can object caching improve the SEO of my website?

A: Object caching alone may not directly improve the SEO of your website, but it can indirectly contribute to better SEO by improving the site’s speed and user experience, which are factors that can impact SEO.

Q: How long does data stay in an object cache?

A: The length of time that data stays in an object cache depends on the cache settings and the expiration time set for the specific data being stored.

Q: How can I clear the object cache if necessary?

A: You can clear the object cache by using the clear cache function in your caching plugin.

Q: Is object caching compatible with all WordPress themes and plugins?

A: Object caching is generally compatible with most WordPress themes and plugins, but some plugins and themes may not work well with certain caching plugins or configurations.

Q: What happens if the object cache is full?

A: If the object cache is full, the cache will start to evict older data to make room for new data. The specific eviction policies and settings depend on the caching plugin used.

Looking to leverage the latest advancements in performance to supercharge your site's user experience?