So let’s talk for a moment about Object Caching (I know it’s a very sexy topic). Regardless of the boring nature of it object caching is something that is very important to any site that has to access a database to get information.
In order to understand why Object Caching is important, you need to first understand what Object Caching is. In this context we will refer to an object as any piece of information fetched from a database and then displayed on a site.
So each time you load a page on your favorite website, that website has to go and fetch the information you’ve requested from a database assuming that website is not a static site which is something we wont cover here.
Now for the most part this isn’t an issue. After all computers are fast and even though Databases are stored on Disk there’s really minimal performance hits to grab this data. The issue with performance comes when you have a site that handles large amounts of traffic upwards of 100’s of 1000’s of requests a second. At that point spinning up a process for the database can get very resource intensive and a lot of the reason behind this is because it has to access Disk and that is a lot slower than accessing data in the RAM.
Now that we understand this you can see where the performance issues would be when serving data from your servers database on each and every page load.
Redis is just one of many technologies that offer in memory object storage. What this means is that when using Redis as a WordPress Object Cache, data is only fetched from the Database once and is then stored in the servers Memory. Then all subsequent requests for the information will be pulled from the server’s RAM instead of from disk meaning there’s no performance loss and no need to spin up a process for the database on every page load. This is an ok thing to do because most of the time the data will be the same between page loads so there’s no reason to go to the database each time to fetch the same information when you can just store it in RAM and then fetch it from there which is much faster.
The beauty of using something like WordPress means that there is a large community of developers who are actively developing plugins to leverage all sorts of functionality and technologies and indeed there is a plugin for integrating Redis with WordPress developed by the team at Pantheon called WP Redis all you have to do to take advantage of this wonderful piece of functionality is number one make sure Redis is installed on your server. If you need to install Redis on your server then i recommend this article detailing the process of getting Redis running on your server. Number two, you need to download the plugin and copy the file object-cache.php into the root of your wp-content directory. Then you can ssh into your server and run the following:
$ redis-cli monitor
If you’ve configured Redis correctly and dropped in the file then you should see the following in your console when loading the site.
Using this you will notice significant speed improvements on your WordPress site.
thanks for reading 🙂