Hit enter to search or ESC to close
Caching is a great way to increase the performance of your site. However, there is one caching technology that is often overlooked: WordPress Memcached.
That’s why we have created this complete guide to Memcached for WordPress sites. While this may be a slightly more technical approach to caching, it is perfect for database-driven systems, including WordPress.
In this post, we will reveal this often overlooked caching mechanism. We will then show you two ways to implement Memcached for your WordPress website. let’s get started!
tl; Doctor: Memcached is a type of caching that can speed up WordPress by reducing the load on your site’s database. Memcached lets you store some information from your database in a cache so that your site can get this information without having to query the database.
Memcached is an open-source distributed memory-caching system. Unlike some other caching solutions, Memcached stores objects in RAM in a persistent manner. Therefore, it is a valuable caching system for dynamic, database-driven websites:
Memcached uses a client-server architecture, which maintains 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, it passes this information to the client without interrupting the database. In this way, Memcached can reduce the number of reads to the database.
If the data is not cached, Memcached will forward the request to the database. After receiving the required information, the caching system will store it in RAM for future use.
Another essential element is Memcached’s Least Recently Used (LRU) algorithm. As the name suggests, it identifies the most requested items based on a ranked list.
Whenever memcached needs to reuse memory, it will remove entries from the bottom of the LRU list. Hence, it prevents the cache from getting out of control and ensures that frequently used data is not deleted.
WordPress stores all your posts, pages and custom posts in a single database. It can use either a MySQL database or a MariaDB one:
Whenever someone visits your website, WordPress will generate HTML pages by running queries in its database. This process is in stark contrast to static sites, where each page is a separate HTML document.
Today, dynamic websites are widely accepted as easy to manage and update. Since they are generated immediately from the server, they can more easily deliver personalized content to individual visitors.
Despite the benefits of dynamic sites, each database request adds load to the server. Querying the database frequently can increase your page load time.
This principle is especially true for websites that generate more complex queries. Also, these requests already add additional latency when fetching information from the database.
Some websites may also have multiple concurrent users who are constantly querying the database. For example, a popular membership site may generate a large number of questions from members at once.
All these database queries can slow down your site and cause heavy load on your server. That’s where Memcached comes in.
Before querying the database, Memcached will check whether the information is already stored in RAM. If a relevant cache is present, the caching system responds to the request without involving the database.
All WordPress sites can benefit from a performance boost. However, as a permanent solution, Memcached is beneficial when you request the same piece of data over and over again. It can also provide a more significant performance improvement when there is a higher cost associated with generating your content.
Memcached is a popular caching solution, so your provider may have already enabled it by default. The easiest way to check is to check your host’s documentation or reach out to their support.
For more advanced users, you can also verify if 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 through your hosting control panel.
Once you are in terminal, you can test your connectivity using the following command:
telnet [ host [ port ] ]
Let’s imagine you want 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 successful, you will see the following message:
Connected to localhost. Escape character is '^]'.
This text informs you that the given port is open. Assuming that you have 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, Memcached is not activated, and it is time to enable it.
Before activating Memcached, it is wise to get a performance baseline. This measurement enables you to see Correct How does the caching system affect your WordPress website?
Different platforms can evaluate the speed of your site. However, GTmetrix provides a detailed analysis of your site’s page loading times. This data can help you determine how well your database is currently performing.
To test your site, navigate to the GTmetrix homepage. Now you can enter your URL and click on Test your site:
GTmetrix will now generate a detailed report, spread across multiple tabs. NS Spring Chart Provides a visual representation of how each asset is loaded on your website:
NS History The tab displays the historical performance of your website based on real-world data. It can be handy to compare 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 different database queries.
Now that you have a performance baseline, it’s time to see if you can shave off a few seconds of your website’s loading time. For some site owners, activating Memcached may be as simple as contacting your hosting provider. Alternatively, you may need to manually install the software on your server. Let’s take a look at both the methods.
Memcached resides on your hosting server. Therefore, before you can use the caching system on your WordPress website, your host needs to have it installed.
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:
If your hosting provider supports Memcached, you can often manually enable this caching system by logging into your hosting control panel.
For example, Siteground customers can activate Memcached by logging in to site equipment, and select supercatcher. From here, you can turn 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 are not sure whether your hosting provider offers Memcached, you can check your hosting agreement or your provider’s official documentation. Alternatively, you can always contact your host for clarification.
Sometimes, you may need to install Memcached manually. For example, your hosting provider may not support this caching system out-of-the-box. Alternatively, you can 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 is wise to install memcached from the 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 to install 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, the command will be slightly different:
yum install memcached
To make sure you are using the correct commands, we recommend that you check the documentation for your particular operating system.
After installing the Memcached software, you can configure it using a plugin like W3 Total Cache:
In the WordPress Dashboard, select Display. Then, click on General Settings:
Now you can activate memcached for page cachehandjob shrink 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.
Let’s quickly recap two ways to set up Memcached on your WordPress website:
Do you have any questions about Memcached and how it can benefit your website? Let us know in the comments section below!
About the author