What It Is and How to Use It (2021) | Cheema Developers Blog

Caching is an excellent way to boost your site’s performance. However, there is one caching technology that’s often overlooked: WordPress Memcached.

That’s why we’ve created this complete guide to Memcached for WordPress sites. While this may be a slightly more technical approach to caching, it’s perfect for database-driven systems, including WordPress.

In this post, we’ll demystify this often-overlooked caching system. We’ll then show two ways to implement Memcached for your WordPress website. Let’s get started!

An introduction to WordPress Memcached (and how it works)

TL;DR: Memcached is a type of caching that can speed up WordPress by reducing the load on your site’s database. Memcached lets you store certain information from your database in the cache so that your site can get this information without needing to query the database.

Memcached is an open-source distributed memory-caching system. Unlike some other caching solutions, Memcached stores objects in a persistent manner in RAM. Therefore, it is a valuable caching system for dynamic, database-driven websites:

The WordPress Memcached solution.

Memcached uses a client-server architecture, which retains a list of available servers. Whenever it receives a query, the caching system checks whether this data already exists in the cache. If it finds a match, then it returns this information to the client without interrupting the database. In this way, Memcached can reduce the number of times a database must be read.

If the data isn’t cached, Memcached will forward the request to the database. After retrieving the necessary information, the caching system will store it in RAM for future use.

Memcached’s Least Recently Used (LRU) algorithm is another essential element. As the name suggests, it identifies the most infrequently requested objects based on a ranked list.

Whenever Memcached needs to reuse memory, it’ll remove entries from the bottom of the LRU list. Therefore, it prevents the cache from growing out of control and ensures that frequently-used data isn’t removed.

Why you may want to use Memcached on your WordPress Site

WordPress stores all of your posts, pages, and custom post types in a database. It can use either a MySQL database or a MariaDB one:

The MariaDB website.

Whenever someone visits your website, WordPress will generate HTML pages by running queries to its database. This process is in stark contrast to static sites, where every page is a separate HTML document.

Today, dynamic websites are widely acknowledged as easier to manage and update. Since they’re generated instantly from the server, they can more easily deliver personalized content to individual visitors.

Despite the benefits of dynamic sites, every database request adds load to the server. Repeatedly querying the database can increase your page load times.

This principle is particularly true for websites that generate more complex queries. Additionally, these requests already add extra latency when retrieving information from the database.

Some websites may even have multiple concurrent users continuously querying the database. For example, a popular membership site can generate a huge number of simultaneous queries from members.

All these database queries can slow down your site and create a heavy load on your server. This is where Memcached comes in.

Before querying the database, Memcached will check whether the information is already stored in RAM. If a relevant cache exists, then the caching system replies to the request without involving the database.

All WordPress sites can benefit from a performance boost. However, as a persistent solution, Memcached is beneficial when you frequently request the same piece of data. It can also deliver more significant performance improvements when there’s a high cost associated with generating your content.

How to check whether WordPress Memcached is enabled

Memcached is a popular caching solution, so your provider may have already activated it by default. The simplest way to check is to consult your host’s documentation or reach out to their support.

For more advanced users, you can also verify whether Memcached is currently running on your server using the Telnet utility.

To access this utility, log in to your server’s SSH terminal. You can often access it via your hosting control panel.

Once you’re in the terminal, you can test your connectivity using the following command:

telnet [ host [ port ] ]

Let’s imagine that you wanted to test the domain “example.com” using port 80. In this scenario, you would enter the following command:

telnet example.com 80

If this test is a success, you’ll see the following message:

Connected to localhost. Escape character is '^]'.

This text informs you that the given port is open. Assuming that you received the desired response, enter the following command:


If Memcached is running, you should see some basic statistics about your connection. If this command fails, then Memcached isn’t active, and it’s time to enable it.

How to establish a performance baseline before activating Memcached

Before activating Memcached, it’s wise to get a performance baseline. This measurement enables you to see exactly what impact the caching system has on your WordPress website.

Various platforms can evaluate your site’s speed. However, GTmetrix provides a detailed breakdown of your site’s page loading times. This data can help you determine how well your database is currently performing.

To put your site to the test, navigate to the GTmetrix homepage. You can now enter your URL and click on Test your site:

Testing your site's performance, before enabling WordPress Memcached.

GTmetrix will now generate a detailed report, which is spread across multiple tabs. The Waterfall Chart provides a visual representation of how every single asset on your website loads:

The GTmetrix dashboard.

The History tab displays your website’s historical performance based on real-world data. It can be handy for comparing your page load times before and after enabling Memcached.

For more advanced users, you can also use the free Query Monitor plugin to dig into individual database queries.

How to set up WordPress Memcached

Now that you have a performance baseline, it’s time to see whether you can shave off a few seconds of your website loading time. For some site owners, activating Memcached may be as simple as contacting your hosting provider. Alternatively, you may need to install the software on your server manually. Let’s take a look at both methods.

1. Contact your hosting provider

Memcached resides on your hosting server. Therefore, before using the caching system on your WordPress website, your host will need to install it.

Fortunately, Memcached is a popular caching solution. For this reason, many hosting services pre-install the software on their servers.

Popular web hosts that install Memcached include A2 Hosting, Cloudways and SiteGround:

Providers such as SiteGround provide WordPress Memcached.

If your hosting provider supports Memcached, you can often enable this caching system manually by logging in to your hosting control panel.

For example, SiteGround customers can activate Memcached by logging in to Site Tools, and selecting SuperCacher. From here, you can toggle Memcached on and off with the click of a button. The SiteGround Optimizer plugin can also help you manage Memcached from your WordPress dashboard.

If you’re unsure whether your hosting provider offers Memcached, you can check your hosting agreement or your provider’s official documentation. Alternatively, you can always reach out to your host for clarification.

2. Install and configure Memcached manually

Sometimes, you may need to install Memcached manually. For example, perhaps your hosting provider doesn’t support this caching system out-of-the-box. Alternatively, you might manage your own server.

Memcached is compatible with most Linux-based servers, so you can install the necessary software using Linux commands. Wherever possible, it’s wise to install Memcached from a package provided by your operating system. This step is important because the tool will typically resolve any dependencies and handle security updates for you.

The process of installing Memcached varies depending on your operating system. For example, Debian and Ubuntu users can set up Memcached using the following command:

apt-get install memcached 

However, if you’re running Redhat or Fedora, then the command will be slightly different:

yum install memcached 

To ensure you’re using the correct command, we recommend checking the documentation for your particular operating system.

After installing the Memcached software, you can configure it using a plugin such as W3 Total Cache:

In the WordPress dashboard, select Performance. Then, click on General Settings:

Enabling WordPress Memcached, using W3 Total Cache.

You can now activate Memcached for the Page Cache, Minify Cache, and Database Cache. Save your settings, and Memcached should now be running on your WordPress website.

You can also find dedicated WordPress Memcached plugins such as Memcached Redux.

Get started with WordPress Memcached in 2021

Let’s quickly recap two ways to set up Memcached on your WordPress website:

  1. Contact your hosting provider.
  2. Install and configure Memcached manually and then use a plugin such as W3 Total Cache or Memcached Redux.

Do you have any questions about Memcached and how it can benefit your website? Let us know in the comments section below!

Free guide

5 Essential Tips to Speed Up
Your WordPress Site

Reduce your loading time by even 50-80%
just by following simple tips.