Tiny WordPress Insights

Recommend Settings for Redis Object Cache Plugin

WordPress Object Cache system allows transients to be stored in object cache backend, such as APC, Memcached or Redis. Without an object cache, the transients are stored in the database itself. This is the default. You could verify this yourself by looking at the (wp_)options table in the database. Fortunately, we have options to store these transients in the memory using one of the backends mentioned above. Among these, Redis has become stable and is production-ready. There are two WP plugins available that use Redis as WP Object Cache. First one is Eric Mann’s plugin. The second plugin is by Till Krüss who forked the former and made it better.

The default settings in Redis Object Cache plugin are enough for most installations. However, it does help to have the following settings to fine-tune it further…

define('WP_REDIS_MAXTTL', '900');
define('WP_REDIS_SELECTIVE_FLUSH', true);
// => https://api.wordpress.org/secret-key/1.1/salt/
define('WP_CACHE_KEY_SALT', '');

WP_REDIS_MAXTTL

By default, the cache keys don’t expire. Considering Redis is persistent in nature, we would want to clear its cache so that it doesn’t get full in no time. It is safe to set it to 900 (seconds). Even for very dynamic sites, we may not want to go below 60 (seconds).

WP_REDIS_SELECTIVE_FLUSH

By default, when it is not set, flushing the cache results in deleting everything in the Redis memory. Oops! You wouldn’t want to delete a rather busy site’s cache from within your personal blog’s dashboard. You may think it may not be needed, if you run only one site. You may be wrong. Your system admin / server admin may have been using Redis to store the (PHP) sessions too! Don’t take things for granted. It doesn’t hurt to set this option to true that will help to delete only the keys are prefixed with WP_CACHE_KEY_SALT (that’s discussed below).

WP_CACHE_KEY_SALT

It is similar to the other keys in wp-config.php file that helps to invalidate the existing login sessions (among others). So, you may generate a key using https://api.wordpress.org/secret-key/1.1/salt/ and that’s it!

Clearing the existing transients in options table

If you are configuring WP Object Cache for the first time (using any backend), you may want to clear the existing transients in the (wp_)options table, using your preferred way. I already shared a standard way of deleting existing transients.

Do you have any further suggestions to improve the default settings?

Exit mobile version