What is Object Caching and How to Use It With WordPress (2024)

When it comes to caching, there are a lot of different types. There’s browser caching and page caching, not to mention mobile and user caching. If you’re using WP Rocket, you are no doubt already benefiting from these types of caching. But another one you’ll want to add to the mix is object caching.

Object caching involves storing database queries and, when enabled on your WordPress site, it can help speed up PHP execution times, reduce the load on your database, and deliver content to your visitors faster.

In this post, we’ll cover what object caching is and how it works with WordPress (including the built-in object caching that WordPress provides). We’ll also look at a few different ways you can implement this type of caching on your site to improve its performance.

What is Caching?

But first, let’s look at what caching is generally to put object caching into context.

Caching is the process of storing frequently-accessed data temporarily in a cache so you can reuse it for subsequent requests.

When someone lands on your site, and you don’t have caching enabled, their browser sends a request for the page to your server. Your server then processes the request, compiles the page, and then sends it back to the browser.

If you have a low traffic site, your server can sit back and relax, so to speak, since it only has to process and compile pages every now and again. But servers hosting large sites have their work cut out for them—they have to work much harder to process and compile multiple pages per second as requests come in.

What is Object Caching and How to Use It With WordPress (1)

This is where caching can help ease the load on your server. It stores a copy of each request and then the next time the same request comes it, it checks the cache and serves it from there. If there’s no copy, the request is sent on to the server to be processed and compiled, and on its way back to the browser a copy is stored in cache.

The beauty of caching is that it saves your server from having to do more work than it has to, allowing it to handle more traffic than it other would. It also has the added benefit of delivering your content faster to users.

If you’re interested to learn more about how caching works, check out Why a Caching Plugin is Critical to Your WordPress Site.

Different Types of Caching

There are two main types of caching: client-side caching and server-side caching.

There are many types of client-side caching, but the one you’re probably most familiar with is browser caching. This is where the browser stores static web page content so the next time someone visits your site, the page is pulled from the cache on their computer instead of being downloaded again.

Object caching is a type of server-side caching. There are lots of types of server-side caching, but the important ones to know about include:

1. Object caching. We’ll go into this in more detail below, but object caching involves storing database queries so that the next time a piece of data is needed, it is delivered from cache without having to query the database.

2. Page caching. Page caching involves storing the entire HTML of a page so that on subsequent views, the content—including files and database queries—can be generated and displayed without WordPress having to do it each time.

3. Opcode caching. Opcode caching involves compiling PHP code between every request. For PHP code to execute, the PHP compiler has to compile the code first and then generate executable code for the server to execute. Opcode caches the already compiled code.

4. CDN caching. Content delivery networks (CDNs) using edge servers around the world to store static website files (i.e., CSS, JavaScript, and media files) for faster delivery to users who are geographically distant from the host server.

So What is Object Caching?

Object caching involves storing database query results so that the next time a result is needed, it can be served from the cache without having to repeatedly query the database.

As a content management system, WordPress is naturally—and heavily—dependent on the database. As such, database efficiency is crucial to scaling WordPress.

If you run a high-traffic site and requests to your pages generate a large number of database queries, your server can quickly become overwhelmed, in turn negatively affecting your site’s performance.

So when object caching is enabled on your site, it can help ease the load on your database and server and deliver queries faster.

What is WP_Object_Cache?

WordPress has a built-in object cache called WP_Object_Cache. Introduced in 2005, it provides a way of automatically storing any data from the database in PHP memory to prevent repeated queries.

However, this object cache only stores objects for a single page load—it discards objects in cache at the end of the request, so they have to be rebuilt from scratch the next time the page is requested.

While this is a useful feature of WordPress, ensuring the database isn’t queried multiple times during a single page load for similar query requests, it’s not exactly efficient.

This is where persistent caching solutions can help. Object caching is more powerful when it can be used to cache objects between multiple page loads.

External persistent object caching solutions like Redis and Memcached make it possible to persist the object cache between requests. This helps speed up the delivery of database queries while further easing the workload of your server.

What are Redis and Memcached?

Persistent object caching is a must if you’re looking to scale. Without it, your site’s performance will slow down as its complexity and traffic increase. The same goes for logged in users and dynamic pages—object caching can help deliver a better and faster user experience.

There are two popular persistent object caching tools worth checking out: Redis and Memcached.

Both of these tools are fast and powerful in-memory data stores that can reduce the load on your site’s MySQL database, while also decreasing the response time of your site and bolstering your site’s ability to scale and handle increased traffic.

Memcached has long been a popular cache choice, but Redis can do everything Memcached can, and with a much larger feature set. Plus, it’s more popular and better supported.

For an in-depth look at the features, pros and cons of Redis and Memcached, this Stack Overflow thread has some great general information about both tools.

How to Use Object Caching with WordPress

The object caching built-in to WordPress is already working on your site by default, so you don’t need to do anything to enable it.

But if you want to take your object caching to the next level so your database queries are cached persistently between page loads, there are a few options available that are straightforward to implement.

1. Use Redis

For Redis-powered object caching, you can’t go past the free plugins available at WordPress.org.

With more than 30,000 active installs, the most popular option is Redis Object Cache. It supports Predis, PhpRedis (PECL), HHVM, replication, clustering and WP-CLI.

Before using this plugin, you’ll need to check that your site is using a PHP environment with the required PHP Redis extension and a working Redis server.

If you’re good to go, this plugin is super simple to install—just activate the plugin, go to Settings > Redis and click “Enable Object Cache.”

What is Object Caching and How to Use It With WordPress (2)

If you run into any problems, again, you’ll need to check with your web host whether the server your site is hosted on is set up for Redis. Since Cloudways hosts my test site, I had to log-in to the dashboard for my site and enabled Redis as a package before enabling object using in the Redis Object Cache plugin.

Alternatively, another option you might want to try is WP Redis, which is a little more involved to set up. Brought to you by the folks at web host Pantheon, this plugin requires that you create a file called object-cache.php and add it to your wp-content folder, and also edit your wp-config.php folder (but only if you’re not a Pantheon user).

If WP-CLI is a big part of your development workflow, you might find it more convenient to use WP Redis since it comes with a variety of commands.

2. Ask Your Host

If you’re on managed WordPress hosting, your host probably offers object caching via Redis. So check out your host’s documentation for information on how to enable object caching, or get in touch to check if it’s available.

Many hosts offer Redis as a feature or add-on—Pantheon, Kinsta and Cloudways, just to name a few.

If you’re on shared hosting, it’s less likely that it will be available for free. In this case, if object caching isn’t available to you, you might want to consider upgrading your hosting package or switching hosts.

Wrapping Up

Object caching provides a relatively simple solution for improving the performance of your database, especially given the fact that WordPress performance is heavily dependent on the speed of your database.

With solutions like Redis, you can quickly enable persistent object caching on your site, whether it’s via a plugin or simply asking your host to activate it.

What is Object Caching and How to Use It With WordPress (2024)

FAQs

What is Object Caching and How to Use It With WordPress? ›

By enabling Object Caching on WordPress, the database query results are stored in a temporary storage called cache, which serves future requests without needing to query the database every time a user makes a request. This whole process reduces the load from the database and server, delivering quicker query results.

How to use object cache in WordPress? ›

To enable object caching via Redis on your site, install the Redis Object Cache plugin and open the Settings tab on your WordPress dashboard. Go to Redis → Enable Object Cache.

Should I enable object cache in WordPress? ›

But another one you'll want to add to the mix is object caching. Object caching involves storing database queries and, when enabled on your WordPress site, it can help speed up PHP execution times, reduce the load on your database, and deliver content to your visitors faster.

How does caching work in WordPress? ›

A site cache, also known as page cache, temporarily stores website data (such as images, webpages, files, and similar multimedia) the first time a web page is loaded. So whenever a user revisits your website, saved elements are quickly retrieved and displayed to them.

What is the difference between object cache and page cache in WordPress? ›

Page cache – Stores the previously generated code necessary to load a page. Object caching – Stores the results of queries to your site's database. Similar to regular page requests, queries can stack up and cause slowness on sites if too many are run at a time.

How do I enable caching on my WordPress site? ›

Go to Site Tools > Speed > Caching > click the toggle button in the Cache column for the desired caching level. It is recommended to use all three levels for production websites.

What are the benefits of object cache? ›

By eliminating the need to access disks, Object Cache avoids seek time delays and can access data in microseconds. This improves performance for dynamic pages and logged-in users. It also provides a number of other features for developers looking to use it to manage queues, or perform custom caching of their own.

Which cache is best for WordPress? ›

  1. WP Rocket. 🥇Best Cache Plugin Overall. ...
  2. WP-Optimize. 🥈Best Free Caching Plugin. ...
  3. W3 Total Cache. 🥉Best Caching Plugin For Advanced Users. ...
  4. LiteSpeed Cache. ...
  5. WP Super Cache. ...
  6. WP Fastest Cache. ...
  7. Hummingbird. ...
  8. Autoptimize.

Does WordPress automatically cache? ›

Clear Cache with a Plugin

They commonly recommend a caching plugin, but these plugins are incompatible with WordPress.com because we automatically provide server-side caching for your site. Instead, you can manually clear your site's cache by following the steps above.

How long does WordPress cache last? ›

By default cache-control headers should be 10 minutes for posts and pages which you can see from the WP Engine menu in the WordPress dashboard. To purge Edge Full Page Cache, use the Clear Network Caches option on the Cache page of the User Portal. Learn more here.

How do I stop objects from caching in WordPress? ›

Locate the WP_CACHE constant in the wp-config. php file and change the value of it from true to false. Save the file to have WordPress caching disabled. define('WP_CACHE',true); > define('WP_CACHE', false);

How often should I clear my WordPress cache? ›

You'll likely want to clear your WordPress cache regularly. This ensures that visitors will always see the newest content, such as comments and recent posts, when accessing your site. Therefore, we recommend purging the cache every 12-24 hours, depending on the frequency of your updates.

Where is the cache stored in WordPress? ›

You will find your website cache inside the wp-content/cache folder.

How do you clear object cache in WordPress? ›

The object cache can be flushed with the WP-CLI command wp cache flush . WP-CLI commands must be run with VIP-CLI. Use caution when flushing the object cache on a production environment. The performance of a site's origin database server is protected by the object cache layer.

Do I need a cache plugin for WordPress? ›

Yes, we strongly recommend installing a WordPress caching plugin, as it can significantly improve your WordPress site's speed. Caching can reduce server load, improve the user experience by reducing load times, and potentially boost your site's SEO rankings due to improved speed.

What happens if I delete cache in WordPress? ›

With this cache in place, the website will load more quickly. This is a useful feature, but one that does take up space. Therefore, clearing your cache means to delete any saved data (such as images or sitemaps) in an attempt to free up room on your server, browser, or device.

How do I enable Redis object cache in WordPress? ›

Method #2: Using the W3TC Plugin
  1. Go to the WordPress Admin → Performance.
  2. Click General Settings → Object Cache.
  3. Mark the checkbox Enable to activate the option.
  4. Select Redis from the drop-down menu.
  5. Click Save Settings & Purge Caches.
Jun 6, 2024

How to use memcache in WordPress? ›

Install Memcached on WordPress (Using a Plugin)

If you use W3TC, you may navigate to the General Settings tab and select Memcached from the dropdown, where it says: Page Cache. Minify Cache. Database Cache.

What is object cache pro WordPress? ›

Object Cache Pro is a business-class Redis object cache backend for WordPress that provides reliable, highly optimized, and fully customizable caching for your website. It's optimized for WooCommerce, Jetpack, and Yoast SEO – making it an ideal solution for businesses.

How do I cache data in WordPress? ›

Plugins like W3 Total Cache, WP Super Cache and Cache Enabler can be easily installed and will cache your WordPress posts and pages as static files. These static files are then served to users, reducing the processing load on the server. This can improve performance several hundred times over for fairly static pages.

Top Articles
Latest Posts
Article information

Author: Golda Nolan II

Last Updated:

Views: 5381

Rating: 4.8 / 5 (78 voted)

Reviews: 93% of readers found this page helpful

Author information

Name: Golda Nolan II

Birthday: 1998-05-14

Address: Suite 369 9754 Roberts Pines, West Benitaburgh, NM 69180-7958

Phone: +522993866487

Job: Sales Executive

Hobby: Worldbuilding, Shopping, Quilting, Cooking, Homebrewing, Leather crafting, Pet

Introduction: My name is Golda Nolan II, I am a thoughtful, clever, cute, jolly, brave, powerful, splendid person who loves writing and wants to share my knowledge and understanding with you.