This website uses cookies

Our website, platform and/or any sub domains use cookies to understand how you use our services, and to improve both your experience and our marketing relevance.

📣 Join the live AMA session with Adam Silverstein on open source and WordPress core! Register Now →

What is Object Caching and How to Use It With WordPress

Updated on September 26, 2023

12 Min Read
What is Object Caching and How to Use It With WordPress

In this digital age where users wish for extra-fast loading speeds, a slow WordPress website can ruin the user’s experience and increase bounce rates.

You certainly don’t want that.

What if we told you there’s a behind-the-scenes superhero ready to expedite your site with the name of Object Caching? Yes, object caching is a powerful tool that significantly affects how quickly your site loads.

Curious to learn more about it? This blog covers everything you need to know about object caching and the steps to enable it on WordPress.

So let’s begin.

What is Object Caching in WordPress?

WordPress websites tend to slow down due to their dependency on the database. Whenever a user requests any page to load or perform any action, the data is fetched from the database to answer the user requests. As a result, the user faces slow loading times and performance issues.

And that’s exactly where Object Caching comes into play. 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.

Built-in Object Caching Mechanism in WordPress

WP-Object-Cache is a built-in object caching mechanism in WordPress that stores new primitives and objects from the database to the PHP memory.

In a standard WordPress installation, the object cache is non-persistent, meaning that the cache is stored in memory and only lasts for the duration of the individual page load. Once the page is loaded, the cache is cleared.

The WordPress object cache is enabled on your WordPress site by default.

Types of Object Caching

Now that you’ve learned about the basics of object caching in WordPress, let’s quickly go through its different types. Object caching is further categorized into two types:

  1. Persistent Object Caching
  2. Non-Persistent Object Caching
Type Persistent Object Caching Non-Persistent Object Caching
Definition It stores data in a way that persists beyond a single request or session’s duration. It stores data temporarily, and this data does not persist beyond the lifetime of a single request or session.
Characteristics
  • Longer lifespan.
  • Variety of storage options, including Redis and Memcached.
  • Requires warm-up time.
  • You can recover cached data after a restart or crash.
  • Short lifespan.
  • Uses the application’s memory.
  • Requires no boot-up time.
Example
  • Redis or Memcached
  • Browser cache
  • Default object caching in WordPress
  • The in-request caching mechanism in many web frameworks.

What Are the Benefits of Object Caching?

While all caching types aim to reduce the server load and enhance the website’s performance, object caching goes beyond this. It has some unique benefits that make it more suitable for particular scenarios.

Here are some of the benefits of object caching:

  • Granularity: Since object caching focuses on individual objects, you can perform targeted caching. This means that when a single piece of data changes, you just need to perform caching on that object rather than the full page caching.
  • Flexibility: Object caching is flexible enough to manage data independently.
  • Reduces Database Load: Object caching can drastically reduce database load by storing frequently accessed data in memory.
  • Decoupling from External System: Object caching provides a buffer layer, allowing applications to function even if the primary data source (like a database) is temporarily unavailable or slow.
  • Application-wide utility: Object caching caches data from various sources, not just databases.

How Does Object Caching Work?

Object caching follows a pretty simple 3-step procedure; here’s a step-by-step breakdown of how it actually works.

Step  # 1: Request for Data

Data is usually available in the database, but with object caching enabled, whenever a user requests certain data, the bot checks for it in the temporary storage (cache), surpassing the primary storage (database).

Step # 2: Check Cache

After the request is made, the bot checks the cache to see if the requested page is available.
The check is usually performed using a key that uniquely identifies the data. This key is normally based on the database query, URL, or some other unique identifier associated with the requested data.

Step # 3: Cache Hit

If the required data is available in the cache, it is called a cache hit, and the data is directly served to the user. If it’s unavailable, the requested page is fetched from the database, where it is kept for future use, and this scenario is called a cache miss.

How Cloudways Uses Object Caching (Server & Application Level)

Cloudways is one hosting provider that gives ample importance to the caching mechanisms. And this is the very reason why Cloudways users get fast performance results.

Cloudways has developed its own WordPress caching plugin called Breeze that takes care of all types of caching, including object caching. It handles object caching both on the server level and the application level. Let’s explore more in detail:

Server Level Caching

Cloudways uses Redis and Memcached as external caching solutions at the server level.

Redis

Redis is an open-source, in-memory data structure store that can be used as an object cache system. Cloudways offers Redis as an optional component on its servers.

Redis is especially useful for database query caching, session storage, and other operations requiring fast access to data.

When enabled, Redis can be used by web applications, like WordPress, to cache objects, reducing the need for repeated database queries.

Memcached

Memcached is a popular in-memory object caching system. By default, it is pre-installed and activated on all Cloudways servers.

Like Redis, memcached significantly reduces database load by caching the results of frequent queries in memory.

Application Level Caching

Cloudways has partnered with Object Cache Pro to leverage cutting-edge Redis-powered object caching and compression technology in WordPress applications, taking caching to another level.

How to Install Object Cache on WordPress

Here’s how you can install Object Cache Pro on your WordPress applications hosted on Cloudways. You can use the plugin for your WordPress, WooCommerce, and Multisite applications. However, please note that it is not included with a standard clean WordPress application.

Remember that Cloudways offers the Pro version on all its 2GB+ plans for free (which is normally priced at $95).

Heads Up!

Be aware that installing Object Cache Pro while having another object caching plugin may create issues. So make sure to manually remove the existing plugin before installing Object Cache Pro.

.
Requirements

  • RAM: A minimum of 2GB or higher. If your current server doesn’t meet this requirement, you can upscale your server to the appropriate size.
  • Package: It’s essential that your server has Redis installed to proceed with the setup.
  • PHP: A minimum of version 7.3 or higher. If your PHP version is below this requirement, you can upgrade it to PHP 7.3 or higher.

Object Cache Pro plugin is pre-installed and activated when you launch a new server with a supported WordPress application. The new server should also meet the mandatory requirements.

If you add any new WordPress applications to the same server, they will also have the Object Cache Pro plugin installed and activated.

How to Install Object Cache Pro on Existing Applications

Follow the steps below to install the Object Cache Pro plugin on your existing WordPress applications:

  • Confirm that your current server meets the necessary requirements for installing the Object Cache Pro plugin.
  • Proceed to install Redis by navigating to the Settings and Packages option.
  • If Redis is already installed, you’ll need to uninstall and then reinstall it.

Redis in Cloudways

  • That’s it! Once Redis is installed, the Object Cache Pro plugin will automatically be configured on all the supported WordPress applications available on that server. If you add any new WordPress applications to the same server, they will also have the Object Cache Pro plugin installed and activated.

Installing Object Cache on a WordPress Application

Installing an object cache plugin on a WordPress application can help improve your site’s speed and performance. Here’s how you can install an object cache plugin to a WordPress application.

  • Log in to your WordPress admin dashboard.
  • Go to Plugins > Add New.
  • Search for your preferred object cache plugin (e.g., “Redis Object Cache”).
  • Once you find the plugin, click the Install Now button.
  • After installation, click the Activate button to activate the plugin.

Redis Object Cache plugin

  • Once the plugin is activated, you’ll be redirected to the plugin settings page, where you need to Enable Object Cache.

Enable Object Cache

  • Once the Object Cache is enabled, you will see the connection information on the same screen, indicating that your plugin is working.
  • You can also flush the cache whenever you want by clicking on the Flush Cache button.

Flush Cache

As the basic version is free, you can upgrade to Object Cache Pro for even better performance and reliability. Again, if you are a Cloudways user using a 2 GB server or above, you get the pro version for FREE.

With Object Cache Pro, you’ll see different interfaces and settings, as shown below.

Object Cache Pro Dashboard

How to Clear the Object Cache Using WP-CLI

WP-CLI is a command-line interface for WordPress. It comprises a set of command-line tools to manage WordPress installations on a server. By default, WP-CLI is pre-installed on all servers deployed on Cloudways.

Here’s how you can clear the object cache using WP-CLI:

Step # 1: Firstly, connect to your server remotely via SSH to use WP-CLI.

Step # 2: Go to your Cloudways server and click on the Launch SSH Terminal button under the Master Credentials tab.

Launch SSH Termianl on Clouodways

Step # 3: It will redirect you to the terminal screen. Enter the Username and Password that you can copy from the Master Credentials tab.

SSH Terminal Cloudways

Step # 4: Navigate to the directory where your webroot is situated, specifically where your wp-config.php file resides. WP-CLI won’t function otherwise. Typically, it’s found in the public_html directory; in this example, we’ll adhere to the default path.

Execute the following command to access the public_html folder:

cd applications//public_html/

Public_html Folder in SSH

Step # 5: Once you’re in the public_html directory and have started using WP-CLI, you can enter the following command to clear the WordPress cache:

wp cache flush

WP Cache Flush

That’s it! You’ve successfully cleared the object cache using WP-CLI.

Testing the Impact of Object Caching on WordPress Sites

I have created an e-commerce store on a Cloudways server to assess Object Cache Pro’s (OCP) performance. I chose the DigitalOcean Premium server for this website primarily because Object Cache Pro is pre-installed on Cloudways servers with a capacity exceeding 2GB.

To optimize the performance testing of OCP, I took the following steps:

  • Disabled Varnish Cache.
  • Deactivated the Breeze plugin.
  • Did not configure Cloudflare to ensure the best possible performance testing conditions.

Here are the server specifications that I used for this setup:

Name Specification
Cloudways Server DigitalOcean Premium
Server Location UK – London
RAM 8 GB
Disk Space 160 GB NVMe Disk
Bandwidth 5TB Transfer
CPU 4 Core Processor
Operating System Debian 10
Nginx 1.21.3
Memcached 1.5.6
Apache 2.4.57
Database MariaDB 10.4.20

We will check the before and after effects of using OCP (Object Cache Pro) on a website. Since OCP is already pre-installed on my site, the first step is deactivating it.

Let’s go through the uninstallation process:

  • Navigate to the Cloudways Platform.
  • Select your server, and access the Manage services section.
  • Here, you will find Redis; click on the Stop button to halt the Redis services, which will automatically deactivate OCP from your site.

Cloudways Settings and Packages - Redis

How to Deactivate Object Cache Pro Plugin from WordPress CMS

You can deactivate the Object Cache Pro plugin on a specific application by following these steps:

  • First, visit your WordPress admin panel and navigate to Dashboard > Home.
  • Next, click Disable inside the Object Cache Pro widget. This action only deactivates the plugin, not uninstall it, so you can always enable it using the same button.

Object Cache Pro Plugin WordPress

Note: Please note that disabling or uninstalling Redis on a server will deactivate the Object Cache Pro plugin on all your WordPress websites hosted on that server.

Object Cache Pro Benchmarking

We conducted a series of benchmarking tests to optimize website performance and evaluate the effectiveness of Object Cache Pro (OCP). These tests aimed to assess the impact of OCP on response times and overall server performance.

Loader.io

I configured the following parameters in loader.io to test the performance of Object Cache Pro (OCP):

  • Test Type: Client Per Test
  • Number of Clients: 100
  • Duration: 1 Minute

First, I disabled OCP on a website by stopping Redis from the Cloudways Platform. Then, I subjected the site to a test with 100 clients for 1 minute. Below, you can see the results:

Before Object Cache Pro

Before – Object Cache Pro

  • The average Response Time is 1056 ms, with a 99% response count.

For the next test, I activated Redis from the Cloudways Platform, enabling Object Cache Pro (OCP) on my site. Once again, I conducted a separate test using the same parameters on loader.io, and here are the results:

After Object Cache Pro

After – Object Cache Pro

  • The average Response Time is 522 ms, with a 100% response count.

So, we’ve got the results:

  • Average Response Time with Object Cache Pro = 522ms
    Average Response Time without Object Cache Pro = 1056ms

In the first test, where OCP was disabled by stopping Redis from the Cloudways platform, we observed an average response time of 1056 ms. This initial benchmark is a baseline for gauging the site’s performance without OCP.

In the second test, we re-enabled OCP by starting Redis, and the results were remarkable. The average response time significantly improved to 522 ms. This demonstrates OCP’s positive impact on reducing response times and enhancing overall site performance.

When Should You Consider Using Object Caching?

Now that we understand the advantages of object caching and how to activate it on your WordPress websites, let’s talk about situations where object caching can be more helpful than other types of caching:

1) Frequent Database Queries

If your app or website constantly asks the database for information, object caching can save time by storing this information for quick access instead of repeatedly asking the database.

2) Dynamic Content

When your website has content that frequently changes or is personalized for each visitor, object caching can help serve this content faster.

3) Complex Computations

Object caching can store the results for websites or applications that perform complex calculations, reducing the need to recompute them every time.

4) Using Third-Party APIs

If you rely on external services like social media or payment gateways that have usage limits, object caching can help you stay within those limits by storing previously fetched data.

5) Microservices Architecture

In systems built with many small, independent services (microservices), object caching can enhance performance by storing commonly used data between these services.

6) Development Flexibility

Object caching allows developers to work with data more easily during development, making it a valuable tool for building and testing.

Remember, Cloudways offers Object Cache Pro for free to users with 2GB plans or higher, which would otherwise cost $95. This means you can take advantage of object caching without any extra cost if you meet this plan requirement.

Use Cases of Object Caching

Object caching is put to work in various real-world situations, including:

  1. Web Content Management Systems: Object caching helps websites that frequently update content, like news sites and blogs, deliver pages quickly to visitors.
  2. E-commerce Platforms: Online stores use object caching to display product listings and handle shopping cart interactions swiftly.
  3. Social Media Platforms: Social networks employ object caching to ensure that users’ feeds load rapidly with the latest posts and updates.
  4. API Caching: Applications that communicate with external services through APIs benefit from object caching by storing responses for faster and more efficient data retrieval.
  5. Gaming Platforms: Online games rely on object caching to enhance performance, offering players a seamless gaming experience.
  6. Financial Systems: Financial applications leverage object caching to quickly retrieve real-time data, which is crucial for traders and financial analysts.
  7. Streaming Platforms: Streaming services such as Netflix and Spotify utilize object caching to deliver videos and music without buffering or interruptions.
  8. SaaS Applications: Software as a Service (SaaS) providers use object caching to optimize their applications, ensuring users have a smooth and responsive experience.

User Testimonials on Object Caching Flexibility:

Website owners appreciate the flexibility that object caching brings to their online presence. They’ve shared their thoughts:

Tweet about OCP 1

  • Speaking of how persistent caching can be better for WordPress and WooCommerce.

Tweet about OCP 2

  • How object caching expedites your site:

Tweet about OCP 3

Tweet about OCP 4

Summary

Object caching is exactly what you need if you face slow load times and performance issues. This blog has comprehensively covered how you can enable object caching on your WordPress site and test the impact of object caching on your website.

If you have any questions regarding this, feel free to leave your queries in the comments below.

Q1. What is the difference between object caching and page caching?

A: Object caching focuses on smaller data chunks like database query results, and page caching is about storing the full rendered output of a page.

Q2. Should I enable the object cache for my website?

A: Yes, if you want to speed up your website and avoid performance issues, you must enable object caching.

Q3. Is Redis an object cache?

A: Yes, Redis is often used as an object cache.

Q4. Is a caching plugin necessary, or is the WordPress cache enough?

A: While WordPress’s default caching mechanisms can be enough for very basic sites but if you want to optimize performance, a caching plugin can provide significant benefits.

Q5. What is a persistent object cache?

A persistent object cache refers to a caching mechanism that saves data across requests over an extended period of time.

Share your opinion in the comment section. COMMENT NOW

Share This Article

Danish Naseer

Danish Naseer is a WordPress Community Manager at Cloudways. He is passionate about designing, developing, and engaging with people to help them. He also actively participates in the community to share his knowledge. Besides that, he loves to watch documentaries, traveling and spending time with family. You can contact him at [email protected]

×

Get Our Newsletter
Be the first to get the latest updates and tutorials.

Thankyou for Subscribing Us!

×

Webinar: How to Get 100% Scores on Core Web Vitals

Join Joe Williams & Aleksandar Savkovic on 29th of March, 2021.

Do you like what you read?

Get the Latest Updates

Share Your Feedback

Please insert Content

Thank you for your feedback!

Do you like what you read?

Get the Latest Updates

Share Your Feedback

Please insert Content

Thank you for your feedback!

Want to Experience the Cloudways Platform in Its Full Glory?

Take a FREE guided tour of Cloudways and see for yourself how easily you can manage your server & apps on the leading cloud-hosting platform.

Start my tour

CYBER WEEK SAVINGS

  • 0

    Days

  • 0

    Hours

  • 0

    Mints

  • 0

    Sec

GET OFFER

For 4 Months &
40 Free Migrations

For 4 Months &
40 Free Migrations

Upgrade Now