You should use a persistent object cache – WordPress Health Check

Table of Contents
Does your site need a WordPress Object Cache banner

“You should use a persistent object cache” is the result of a new health check introduced in WordPress 6.1. This article will explain why you’re seeing this recommendation and what you can do to fix it, if you need to at all.

wordpress persistent object cache health check screenshot

 

How does WordPress Health Check know if I need a Persistent Object Cache?

As of WordPress 6.1, a new specific Cache Health Check has been added. There are two health checks, a Full Page cache check and also a Persistent Object Cache check.

Basically, the object cache uses a set of “tests” to decide if an object cache would be beneficial.

Here are the variables that are used:

 * Override the whole $thresholds array, or any specific indexes as required.
*/
add_filter( 'site_status_persistent_object_cache_thresholds', function( $thresholds ) {
$thresholds = array(
'alloptions_count' => 600,
'alloptions_bytes' => 200000,
'comments_count' => 2000,
'options_count' => 2000,
'posts_count' => 2000,
'terms_count' => 2000,
'users_count' => 2000,
);
return $thresholds;
} );

We’re not going to go into each variable here, but we don’t necessarily agree this is the only way you would test if a site would benefit from an object cache. As mentioned before, if a site doesn’t create dynamic content on a per-user basis it’s unlikely an object cache is the source of its performance issues. A page cache in this scenario would be much more beneficial. That said, there are certainly lots of cases where a site can benefit from Object Caching.

What is a Persistent Object Cache?

Persistent Object Caches are specialized servers such as Redis or Memcached that provide an in-memory data structure store which is perfect for certain kinds of caching.

In the WordPress world, the most common use for object caching is as a database or MySQL query cache. So for example, where a particular section of code will have to go and look at the WP_Options table many times, the results of this query can be cached in memory in your Object Cache. The next time the query results are needed, you hit up your object cache and get them almost instantly. While database servers employ their own caches, they very often still need to refer to disk and calculate the results which may take longer.

Like with any caches there is a trade-off for increased performance but older stale data. If you set your cache to not live for very long, then more queries are thrown at the database and the benefit of the cache is somewhat negated.

A page cache removes the requirement for any type of data lookup whatsoever in terms of queries, as the page has already been created and cached. The next time someone requests the page, the web server (or reverse proxy caching server) serves the page up itself without invoking any PHP, Mysql etc. In this scenario, an object cache wouldn’t help.

Where object caches really shine, is where Page caches can’t be used. For example, if you’re running a woocommerce store and we have a logged-in user adding items to their cart and accessing account information, a page cache can’t help us as this content is unique to the user. However, an Object cache could help us with queries that are accessed more than once.

 

How do I add a Persistent Object Cache to WordPress?

To add a persistent object cache you will need to make sure your site has access to a Redis or Memcached server.
Once that’s the case you can use a plugin on WordPress to enable the use of the object cache. Here are some popular options:

 

Is it time for a better WordPress host?

You might also like..

Are you wasting money on your current hosting provider?

Related Posts