Conditionally avoid using the persistent storage backend with WP Object Cache

One common strategy for improving WordPress’ performance is to use a service like Redis or Memcached as a persistent storage backend for the WP Object Cache. This lets you more easily cache the result of expensive data generation.

However, there are cases in which you don’t necessarily want all of your object cache to end up in the persistent storage backend. For instance, if you have hundreds of cache calls on a pageload and each call takes 1 ms of network requests, you may want to prevent some of them from occurring. Enter: non-persistent groups.

First, make sure your calls to wp_cache_add( $key, $value, $group ); and wp_cache_set( $key, $value, $group ); include the third group argument. Then, to mark a group as non-persistent, use wp_cache_add_non_persistent_groups( $group_name );.