View Categories

What Is Memcached, and Why Does My Site Need It?

  • Mar 17, 2021
  • 0
  • by A2 Marketing Team

It’s impossible to overestimate the impact caching can have on your website’s performance. However, there are multiple different types of caching, and various caching solutions to choose from. This means many WordPress users are unsure where to start with caching, or even whether they need it at all.

A fast site is essential for providing a great user experience – it improves your search engine rankings, and drives conversions. While caching may be slightly technical, it can also help you achieve all of these goals, and more.

In this article, we’ll demystify caching for your WordPress website. We’ll explore what caching is, and the various options available. We’ll then dive into a caching solution that’s less commonly discussed, but could deliver real benefits to your WordPress website. Let’s get started!

What Caching Is (and Why It’s Important)

By default whenever someone lands on your site, their browser sends a request for the page to your server. The server then processes this request, compiles the page, and sends it back to the browser.

If your site has relatively low traffic, your server may be able to process each request without having a noticeable impact on your site’s performance. However, as your site grows your server will have to work harder to process the growing number of requests. This may start to affect your website’s performance.

Caching is the process of storing frequently-accessed data in a temporary cache. Every time a visitor requests this data, it will be served from the cache rather than the server. This reduces the strain of the latter.

If the data hasn’t already been cached, the request will be sent to the server. However, on its way back to the browser, a copy of this data will be stored in the cache. This ensures a cached copy is available the next time someone requests this content.

Caching can boost your website’s performance, even when it’s experiencing heavy traffic. This makes it easier to scale your site, and handle unexpected spikes in traffic.

Caching also helps you provide a better visitor experience by delivering content faster. Since visitors are having a positive experience on your site, they’re more likely to take positive actions, such as subscribing to your newsletter, or purchasing a product. This will hopefully boost your conversions and revenue.

Search engines such as Google also use page speed as a ranking factor. This means caching can have a positive impact on your Search Engine Optimization (SEO). Climbing just one place in Google’s results can increase your Click-Through Rate (CTR) by over 53 percent, making SEO a crucial way to grow your audience.

The Different Types of Caching (and Their Benefits)

There are various caching solutions for you to choose from. While they typically follow the same general principle, specific solutions may work differently in practice.

With some caching solutions, data is stored locally on the person’s computer the first time they visit your website. On subsequent visits, this data can then be loaded from their local storage. This will improve page load speeds. However, as the saying goes you never get a second chance to make a first impression! If the visitor’s first impression is a slow, unresponsive website, they’re unlikely to come back for more.

Other solutions provide external locations that store cached versions of your site, most notably Content Delivery Networks (CDNs). These locations are often physically distributed, providing convenient local access points for your global audience. A visitor’s browser will request the cached data from the access point that’s physically closest to them. This will often improve your page load speeds, compared to communicating with a server that may be located thousands of miles away.

The available caching solutions may vary depending on how you’ve built your site. For example, if you’re using a popular platform such as WordPress, you’ll have access to a range of dedicated caching tools.

The A2 Optimized plugin, with Memcached settings.
You can configure Memcached, using a plugin such as A2 Optimized.

Some hosting providers also offer their own caching solutions. To help you create a high-performing website, you may want to opt for a provider that offers caching as part of their hosting plans.

How ‘Object Caching’ Can Improve Your Website

Memcached is classed as an object caching system. Before we take a closer look at Memcached in particular, it can help to have an overview of object caching.

As a Content Management System (CMS), WordPress is heavily dependent on its MySQL database. This means database efficiency is crucial to delivering a high-performing WordPress website, particularly as the number of people visiting your site grows.

Every time someone makes a request to your website, it generates a database query. If your site receives a large number of requests to the database, it could overwhelm your server. This could result in a drop in performance, or may even knock your website offline.

Object caching is a type of server-side caching that stores database queries. The next time a particular piece of data is requested, it’ll be delivered from the cache without having to query the database. This means your server won’t have to regenerate the results of database queries every single time someone requests a particular piece of data.

There are various technologies you can use to store an object cache. This includes Memcached, but also WordPress’ WP_Object_Cache class.

WordPress’ Built-in Solution (and Why You Need Extra Object Caching)

WordPress has its own object caching class, known as WP_Object_Cache. This built-in object caching solution saves a copy of the most complex and frequently-used queries running on your website. It then stores these results in a database table.

In this way, WP_Object_Cache ensures the database isn’t queried multiple times during a single page load for similar query requests. However, at the end of each request, WP_Object_Cache discards all the objects in its cache. This means objects will have to be built from scratch the next time the page is requested.

For the greatest performance benefits, you’ll want to retain the object cache between multiple page loads. This is known as persistent object caching, as the object cache persists between requests.

Instead of caching every page or object all the time, persistent object caching enables you to cache objects once, and serve them as needed. This makes persistent object caching particularly important for sites that feature large amounts of recurring content. There are a number of persistent object caching solutions available for WordPress, including Memcached.

An Introduction to Memcached

Memcached is an open-source persistent object caching tool. This essentially means Memcached stores objects so they can be reused between page loads. Memcached keeps its data in Read Access Memory (RAM), which reduces the number of times the database needs to be read.

Memcached caching solution.

Memcached belongs to the NoSQL family of data management solutions, and stores all of its data based on key-value pairs. This includes API calls and the results of database calls.

As a persistent object caching solution, Memcached is particularly useful when the same piece of data is requested frequently. For example, your site might feature lots of recurring content. Memcached can also deliver a significant performance boost when the cost of generating a particular piece of content is high.

By using Memcached in addition to WordPress’ built-in WP_Object_Cache class, you can significantly reduce the strain on your site’s MySQL database. This can reduce your response times and your page load times, even when your site is experiencing a large volume of traffic. It can also help your website manage unexpected spikes in traffic, including the infamous Reddit ‘Hug of Death’.

How the Memcached Object Caching Solution Works

Memcached uses a client-server architecture based on four components. The first component is a client-server, which retains a list of available Memcached servers.

Whenever the client-server receives a query, it first checks whether this data exists in the cache. If the data is already available, Memcached returns it to the client without interrupting the database. If the data isn’t cached, Memcached forwards the request to the database.

To help distribute the load, a typical Memcached implementation consists of multiple servers and clients. Memcached uses a client-based hashing algorithm to match each request to an appropriate server.

There’s also the Memcached server software, which stores the key/value combinations for various objects. This includes API calls, page rendering, and the results of database calls. Memcached stores these key/value combinations in an internal hash table.

Finally, Memcached has a Least Recently Used (LRU) algorithm. This algorithm helps prevent the cache from growing indefinitely, by identifying least recently used objects.

LRU works on a linked list. Whenever a list entry is accessed or updated, it gets removed from the list and attached to the list head. This means the entries at the bottom of the list are less recently used than items at the top of the list. Whenever Memcached needs to reuse memory, it’ll remove entries from the bottom of the list.

The Benefits of Using Memcached on Your WordPress Site

Memcached stores the results of a database query. As such, whenever a visitor requests the same query again, Memcached can respond without having to process the query.

In this way, Memcached can significantly improve your website’s performance, and reduce page load times. Studies suggest that 40 percent of people abandon a website that takes longer than three seconds to load. Memcached can help you avoid losing a significant chunk of your audience, due to slow page loading times.

Fast, responsive websites also generally deliver a better overall visitor experience. Since visitors are enjoying their time on your site, they’re more likely to visit multiple pages. This increases key performance metrics, such as session duration and total number of pages visited. It also increases the chances of repeat visits, and conversions.

There’s also evidence to suggest that search engines use speed as a major page ranking factor. By reducing your page load times, Memcached can contribute positively towards your SEO. This can increase your search engine rankings too.

Studies suggest that Google’s first five organic search results receive over two-thirds of all clicks. By using Memcached to boost your site’s performance, you could significantly increase your organic traffic.

Every request that the database has to process adds load to the server. Before sending a request to the database, Memcached checks its memory. If a relevant cache exists, Memcached replies to the request without involving the database. This reduces the load on your server, which can help your website handle larger volumes of traffic. This includes unexpected spikes in traffic.

How to Use Object Caching With WordPress (in 3 Easy Steps)

Memcached resides on your hosting server. Given this, before you can use Memcached, your hosting provider will need to install it.

At A2 Hosting, we’re happy to get you up and running with Memcached. A2 Hosting customers can open a support ticket through the Customer Portal, and we’ll handle the rest.

Once Memcached is successfully installed on your system, let’s see how you can configure it. In this section, we’ll also show how measure the impact object caching has on your site.

1. Get a Performance Baseline

Before enabling Memcached, it can be useful to get a performance baseline. This enables you to measure the impact Memcached has on your WordPress website.

There are various platforms you can use to measure your website’s performance. However, GTmetrix provides a detailed breakdown of your site’s loading metrics. This can be particularly useful for evaluating page load times.

To see how well your site is currently performing, head over to the GTmetrix home page and enter your site’s URL. GTmetrix will then generate a detailed report of your website’s performance.

A performance report, created before implementing Memcached.

This report is divided into several tabs. The Waterfall tab displays a visual representation of how every single asset on your website loads. This includes your CSS, HTML, JavaScript, images, and plugins. You can use the provided waterfall graph to analyze how each asset is impacting your site’s loading times.

The GTmetrix performance testing tool.

The History tab displays your site’s historical performance. You can use this tab to compare your page load times before, and after enabling Memcached.

GTmetrix's History tab, before implementing Memcached.

While you can analyze your website for free, GTmetrix Pro is also available. This Pro package adds some extra features, including resource usage graphs, hourly monitoring, and unlimited custom filters for your reports.

2. Use a Dedicated Plugin

At A2 Hosting, we offer Memcached via our A2 Optimized plugin. This is the easiest way to configure Memcached for your A2 Hosting account. Using A2 Optimized, you can configure CSS, HTML, and JavaScript minification. You can also enable database, object, and page caching.

After installing and activating the A2 Optimized plugin, navigate to Plugins > Installed Plugins. On this page, find the A2 Optimized plugin and select its accompanying Settings link.

The A2 Optimized Memcached plugin.

You can then select Begin installation > Activate > Start Configuration. A2 Optimized will now scan your site and suggest some ways to improve your website’s performance.

A2 Optimized's Memcached settings.

To activate Memcached, scroll to the Memcached section and select Enable. Memcached is now up and running, and will start caching your data.

Alternatively, you can configure Memcached using a caching plugin such as W3 Total Cache. W3 Total Cache is a web host agnostic Web Performance Optimization (WPO) framework that’s compatible with a range of hosting solutions. This includes shared hosting, dedicated hosting, and Virtual Private Servers.

To enable Memcached using W3 Total Cache, activate the plugin and navigate to Performance > General Settings. Next, open the Page cache method drop-down, and select Memcached.

The W3 Total Cache Memcached plugin.

Then, open the Minify cache method drop-down, and select Memcached. Finally, open the Database cache method drop-down, and select Memcached. Save your changes, and Memcached will now be enabled across your website.

3. How to Re-Test Your WordPress Website’s Performance

After activating Memcached, you may want to test your website’s performance. This can help you evaluate the impact Memcached has on key metrics, particularly page load times. You can re-run GTmetrix, and compare the results using the tool’s History tab.

By re-examining your site’s performance, you may identify other areas where you can improve. As we mentioned earlier, there are multiple approaches to caching and various caching solutions available. To further boost your website’s performance, you may want to consider implementing a CDN, or using a dedicated caching plugin.

If you opted for the A2 Optimized plugin, we recommend exploring some of its additional features, particularly TurboCache. When a page is requested for the first time, TurboCache stores a static copy of the page’s HTML output. The server will then use this cached copy for subsequent page requests, instead of running the page’s scripts and database queries repeatedly. This can further improve your site’s performance.

Conclusion

When it comes to optimizing your WordPress website, caching plays a crucial role. Although it may seem like a technical subject, with a help from your hosting provider you can get advanced caching solutions such as Memcached up and running on your WordPress website.

Memcached is a caching mechanism that resides on your hosting server. As such, the first step to enabling Memcached, is to contact your hosting provider. Once they’ve enabled Memcached, you can use an optimization plugin to activate and configure this advanced caching solution.

There are many elements that contribute towards your site’s performance, including your choice of hosting provider. At A2 Hosting, our Turbo Servers can boost page loading speeds by up to 20X, compared to competing WordPress web hosting providers. When used in combination with caching, this can supercharge your WordPress website.

Image credits: Unplash.

The A2 Posting