WordPress Acceleration using NginX Reverse Proxy & Caching
27 May 2019What is Plus Addressing?
11 June 2019Memcached is a general-purpose distributed memory caching system. It is often used to speed up dynamic database-driven websites by caching data and objects in RAM to reduce the number of times an external data source (such as a database or API) must be read. Source: Wikipedia
In simple terms it means that it will save the queries in RAM that help in reducing the database load resulting in a fast loading web page. Using Memcached for WordPress website would significantly improve the performance and reduce the page load time.
Most of the internet giants rely on Memcached to boost the page load time. Sites like YouTube, Reddit, Facebook, Twitter, and Wikipedia are using Memcached. Our offering of Highly Optimized WordPress Hosting is using Memcached to boost the performance of WordPress.
Memcached is not the only
In this post, we’re going to explore the secrets of object caching and dive into one of the most popular object caching systems: Memcached.
Memcached shouldn’t be confused with memcache, which is a PHP extension created for Memcached caching service, and it’s out of the scope of this post.
What is Memcached Used For?
Before getting into the details of Memcached, let’s explain what object caching does precisely.
If page caching takes care of caching static resources (images, HTML, CSS and JS files) and browser caching manages the same resources within the browser, object caching is devoted to your database.
The aim of object caching is to cache query results from your database. You can find a detailed explanation of what object caching is on our blog. Memcached is used for speeding up dynamic web applications like e-commerce stores, registration/login websites, etc. by reducing the database load. It stores the processed result so whenever a visitor requests the same query again, Memcached can respond to that instead of processing the query and reply. By keeping the server(s) less busy, your visitors will experience a faster loading time and better user experience.
An efficient database is one of the crucial factors for a fast website: WordPress is a content management system which is naturally dependent on its MySQL database.
Every time users (or crawlers) make a request on your website, they generate database queries. If your site experiences a large number of requests to the database, queries can quickly pile up, overwhelming your server and slowing down your website.
The good news is the WordPress introduced its object caching class a long time ago: it was 2005 when the class named WP_Object_Cache was implemented into WordPress core.
How Does Memcached Work?
Every time a visitor/browser requests the server that requires the database to process and respond, it adds load to the server. Memcached reduces that load by storing data objects in temporary dynamic memory. It saves the data on key-values and checks its memory before sending the browser’s request to the database. If a cache is present, it replies to the request without involving the database to process.
Memcached uses a client-server architecture based on four components:
- A client-server, which retains the list of available Memcached servers
- A client-based hashing algorithm, which picks up a server based on the requested “key.“
- A server software, which stores the combinations of values + key into an internal hash table
- A Least Recently Used (LRU) algorithm, which decides when to use old data or the memory
When an item is requested, Memcached validates its expiration time to see if the item is still valid before replying to the request. If a cache is not present, it sends the request to the database to process and store the result as an item
If a server becomes out of the memory, it looks and replaces the expired items. If it still needs any information, it looks for the items not requested for a particular period. By this, Memcached keeps more recently requested information in dynamic memory.
To break it down more simply Memechached in high levels uses the following 5 steps:
- The client-server receives a query from a user (i.e., access to a specific URL of a website with an HTTPS redirect);
- The client-server checks with the Memcached server if the data needed is already stored in its memory;
- If the data exists, Memcached directly returns it to the client server;
- If the data isn’t already saved in the cache, Memcached forwards the request to the database;
- Requested data is now forwarded to the client-server and, at the same time, the Memcache index is updated with these latest values: the cache is now ready to be used in the future (see step 3).
How can I optimize my WordPress Using Memcahced?
First, it must be installed on your hosting server and then your application should be able to support Memcached. Most of the Hosting Providers are not able to support Memcached. We have got Memcached built in for Highly Optimized WordPress Hosting.
The second condition is that your web application can support Memcached. Since Memcached is solely relying on RAM, it doesn’t require too many CPU resources. Our Highly Optimized WordPress Hosting is designed to ensure that Memcached has got enough RAM to perform.
There are plenty of WordPress cache plugins available on the market. Most of them support Memcached like W3TC, one of the most widely used cache plugins allow you to configure Memcached. If you are one of the W3TC users, navigate to the General Settings tab and select Memcached from the dropdown, where it says:
- Page Cache
- Minify Cache
- Database cache
When you get our Highly Optimized WordPress Hosting, you will be we provide you with Pre-configured memcached redux plugin for WP.
What Are The Benefits Of Using Memcached On Your WordPress site?
The main advantage of Memcached is that all information is stored in RAM: this means it doesn’t need to be loaded from the disk each time. This makes data available to your users much faster. Helps to reduce TTFB etc. Makes your WordPress site run
With Memcached there are no data restrictions: it can used to cache a number of different data, such as documents, images but, above all, much more complex structures. So all your static files like images, video etc can also be served via
Final Thoughts
Memcached is considered as one of the ways to speed up a WordPress site if configured properly as it reduces the database load and keeps the server(s) less busy resulting in better performance and page load time.