Home » E-Commerce » Improve your WordPress performance with object cache!

Improve your WordPress performance with object cache!

Wordpress Object Cache En

Over the course of my various articles on WordPress performance, you have surely retained that it is necessary to set up a powerful cache system on your WordPress website or WooCommerce online store.

This cache essentially concerns the web page itself as well as static resources such as JS and CSS files. However, we hear less about the object cache, which can be a perfect complement.

What is object cache?

The object cache stores the results of queries from the database so that they are delivered from the cache the next time it is needed. This speeds up PHP execution times and reduces the load on your WordPress database. Especially convenient case of large traffic load!

WordPress offers a default object cache, WP_Object_Cache, however it is not powerful and efficient enough to have real performance gains.

What are the benefits of object caching?

As I said in the introduction, the object cache is not a duplicate of the “page cache” but is complementary to a cache module such as WP Rocket or WP Super Cache, to name a few.

Apart from relieving the use of the database in general, setting up the object cache can have an impact on pages and areas of your site or online store that are excluded or not cached by the page cache. This therefore includes the back office / administration but also pages such as the shopping cart, member areas and other parts very “dynamic” in terms of data.

Setting up the object cache will also have a beneficial effect on server response time, commonly referred to as TTFB.

How do I set up the object cache?

Setting up the object cache can be relatively simple if you are used to putting your hands in the mud a little, otherwise you will probably have to call on a WordPress freelancer who will be able to take care of it.

Typically, both cache systems cited objects its Memcached or Redis. I am rather Redis team, for its efficiency, flexibility and possibilities more numerous than its “competitors”.

For these multiple operations and if you want to carry them out yourself, you will need to have a dedicated server, VPS or hosting on which you have access to a command line or a host that offers this kind of services.

Install Redis on the server

To start, you must therefore install Redis as well as the package necessary to interface with PHP, PHP Redis:

apt install redis-server php-redis

We quickly test if the installation is going well by typing the redis-cli command in your terminal, then type ping. If you get a PONG return, it’s because everything is OK at the moment!

Quick Redis Server Setup

Access to the Redis configuration file is:

nano /etc/redis/redis.conf

Change these values:

maxmemory 256mb #La maximum size of redis cache you want to allocate
maxmemory-policy allkeys-lru #Permet replace old values with new ones 
requirepass YOUR PASSWORD

To account for these values, restart the Redis server: redis-server restart service

Configuring and Enabling object cache on WordPress

Now that everything is ready at the server level, all that remains is to configure WordPress and activate the object cache on it in order to speed up your site or online store! 🚀

First, install the WorPress plugin: Redis Object Cache

Next, edit the wp-config.php file at the root of your WordPress installation and insert the following lines right after the line define('DB_COLLATE', '');

define('WP_REDIS_HOST', '127.0.0.1');
define('WP_REDIS_PORT', '6379');
define('WP_REDIS_PASSWORD', 'YOUR PASSWORD');
define('WP_CACHE_KEY_SALT', 'nom_de_domaine.tld');

The WP_CACHE_KEY_SALT line is important, it corresponds to the site prefix for the cache data. Indeed, if you have multiple sites on your server or hosting and you want to enable Redis for each of your sites, it is important to differentiate the values for each site so that Redis does not send data from one site to another.

Finally, all you have to do is go to the configuration page of the Redis Object Cache plugin and click on“Enable Cache”.

It’s operational! 🚀

Monitor your Redis cache

Small tip, if you want to know the size of the Redis cache (size that you configured earlier, 256mb in my example),you can type these commands:

redis-cli
auth YOUR PASSWORD
Info MEMORY

If you want to see what Redis caches or reuses from the cache

redis-cli
auth YOUR PASSWORD
monitor

Join 1,658 other subscribers

Conclusion

You now know almost everything about the item cache and you are able to set it up on your site or online store.

The health and performance of your site will be better! Your site will be faster and your data base will be relieved during high attendances. To sustainably improve the health / sustainability of your site,

Do not hesitate to share your results or difficulties in comments 😀!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.