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?
Why WP_REDIS_SELECTIVE_FLUSH is not mentioned in the WP official plugin page?
https://wordpress.org/plugins/redis-cache/
Probably, Till has forgotten to update the readme in wp.org repo. I got it from its Github repo at https://github.com/tillkruss/redis-cache (under configuration-parameters) where more information is available than what’s available at wp.org repo.
Is it okay if I set WP_REDIS_MAXTTL = 43200 (12 hours) ?
Yes. Perfectly okay for a small site. For a busy site, it can lead to high memory usage.
I have Redis object cache enabled, but transients are still save to wp_options table.
Can’t figure this out.
I noticed something similar too. Around 1% of the transients are still being sent to wp_options table.
Do you know why this message appears when I click flush cache button:
Object cache could not be flushed.
Sorry for the (long) delayed reply. Unfortunately, I don’t use this plugin anymore due to its recent move towards freemium model.