When it comes to caching, there are a two primary types: Page and Object Caching. At DIHOST, page caching is already enabled on all web hosting packages, while object caching needs to be set up manually. In this article, we will look into object caching in depth and explain how to configure your WordPress site.
But before we begin, let’s have a quick look at what Object and Page Caching is.
What is Page Caching?
In simple terms, page caching refers to the process of creating static versions of your content or (dynamic) website, and serving that to visitors. WordPress is, mostly, dynamic. The content of each and every page is built at the time of request from the visitor, and that’s a lot of work.
Imagine having hundreds of visitors trying to open your website: Without caching, the server will have to process each request (simultaneously or one by one) by utilizing a lot of resources like CPU power or memory, generating a very high load to the server.
This is where caching can help ease the load on the server. By enabling page caching on the server, it will generate a static copy of the result/page that was previously generated on the server, and serve it to all next visitors requesting the same page. Returning a static copy to all new visitors almost does not require any server resources, allowing the server to serve more visitors simultaneously or to process other pages that have not been cached more quickly.
What is Object Caching
Other than page caching, where a static copy of a dynamically created page is returned to new visitors to prevent the server to generate the page over and over again, object caching is a process that stores database results in order to quickly bring them back up next time they are needed.
The database holds all your WordPress configuration, pages, posts and other data (except images and similar static content). On every page load, this data is retrieved by querying the tables in the database. Queries can stack up and cause slowness on sites if too many are run at a time.
Object Caching takes those (repeated) queries and stores the results in a so-called Object Cache. This speeds up the operation so the server doesn’t have to generate a new result over and over again.
How to enable Object Caching in WordPress
It is recommended to use persistent object caching in WordPress if you have a lot of repeating content or if you are trying to scale your website. We will not just enable the WordPress build-in object caching functionality, we will use an external caching solution that helps persist the object cache between requests.
Some popular persistent object caching tools are Redis and Memcached. In this article we will cover how to use Memcached, as it is available on all DIHOST cloud packages.
Memcached is an in-memory high-performing object caching system. It stores data objects in dynamic memory. Due to being specifically designed to do object caching for web pages, makes it the fastest object caching solution out there.
There are many cache plugins available on the market, and most of them support Memcached like W3 Total Cache. If not installed already, install it using the WordPress plugin installer. Afterwards, navigate to the General Settings tab and select Memcached from the dropdown in the Page Cache section.
Save the changes and you are done.