Redis Object Cache for WordPress / Cache de Objetos Redis para WordPress
What is Redis Object Cache and how to use it for your WordPress website?
Redis and object caching can vastly speed up your WordPress page load times with each subsequent visit. It’s also used by many popular websites like GitHub, Pinterest, StackOverflow and many others.
Remote Dictionary Server (Redis) “is an open source, in-memory data structure store used as a database, cache, and message broker.” It’s a key-value store which is often called a NoSQL database.
It’s best used on dynamic websites such as WordPress sites when it comes to object caching, which caches repeating query results.
A Quick Refresher: What is Caching?
If a web page is cached, it means that elements of that page such as images, stylesheets, and other content is loaded once, then stored in what’s called a "cache".
It memorizes what was loaded, creates a static version of it, then can serve that version much faster the next time that page is loaded.
The result is faster page load times and less of your server’s resources being used.
What is Object Caching?
Object caching is a type of server-side caching. This means the caching is administered at the server level, and isn’t controlled by the end user or a system they use for caching. Object caching stores database query results that have been loaded. Then, it serves them up faster the next time they’re requested so the database doesn’t have to be queried again.
WordPress also has object caching built-in with the WP_Object_Cache class.
The trouble is, the inherent object caching WordPress has isn’t persistent by default. This means that cached data is only stored for as long as the request to the database lasts, which is ultimately no more than for one page load, and inefficient.
If you were to install and use a persistent object caching solution such as – ehem – Redis, for example, data could be cached for all subsequent page loads, giving your database more of a break.
Who Needs Object Caching?
If your WordPress site is static and all it needs to load are a stylesheet and some images, for example, you’re not going to see any difference in you use object caching.
Conversely, a dynamic site loads tons of data across pages that are stored in your database such as user details, taxonomies, links, and other similar data.
As previously mentioned, every time a page loads that content, it sends one (or often several!) database queries. If you use object caching, that data is stored in the cache and it’s ready to be displayed on the page in the flashes of flashes.
Your database can be queried much less often and retrieving content from the cache is a lot faster than sending queries to the database.
This results is page loading times that are a lot faster. Your server’s resources are also used more efficiently. This is an especially crucial factor if you’re looking to scale your WordPress website.
So, if your site gets a lot of traffic or you’re expecting it will soon, and it’s dynamic, you should consider using object caching.
How to enable Redis Object Cache on your Website?
Before you can start to use Redis Object Cache on your website, you need to enable it on the Web Server:
- Login into the Directadmin control panel: https://cp.xrv.pt:2222
- Now, go to the Functions menu, click on Advanced Features and click on Redis:
- Enable the Redis Service and take note of the path to the socket file (we will need it later):
How to enable Redis Object Cache on your WordPress?
At this moment, we have enabled the Redis service on the web server. Now it's time to enable it on the Wordpress.
Because Wordpress doesn't come natively with support for Redis, we will need to install a plugin. In this article we will explain how to configure the Redis Object Cache for WordPress plugin.
- Login into your WordPress admin.
- On the WordPress menu, click on Plugins and on Add New Plugin:
- On the Add Plugins page, search for "Redis Object Cache for WordPress" and click on Install Now for the Redis Object Cache plugin: