From 6bea9e0ece36513ddd79e873e5ca6c7e7a27d824 Mon Sep 17 00:00:00 2001 From: Jan Thiel Date: Thu, 21 Oct 2021 14:40:51 +0200 Subject: [PATCH] Adds constant to filter global caching groups Setting an array value to WP_REDIS_IGNORE_GLOBAL_GROUPS removes these caching groups from the global caching group array and prevents them from being set. --- object-cache.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/object-cache.php b/object-cache.php index 537a516..6122418 100644 --- a/object-cache.php +++ b/object-cache.php @@ -21,6 +21,10 @@ define( 'WP_REDIS_DEFAULT_EXPIRE_SECONDS', 0 ); } +if ( ! defined( 'WP_REDIS_IGNORE_GLOBAL_GROUPS' ) ) { + define( 'WP_REDIS_IGNORE_GLOBAL_GROUPS', false ); +} + /** * Adds data to the cache, if the cache key doesn't already exist. * @@ -430,6 +434,11 @@ public function add( $key, $data, $group = 'default', $expire = WP_REDIS_DEFAULT public function add_global_groups( $groups ) { $groups = (array) $groups; + // Filter global groups + if ( is_array( WP_REDIS_IGNORE_GLOBAL_GROUPS ) ) { + $groups = array_diff_key( $groups, WP_REDIS_IGNORE_GLOBAL_GROUPS ); + } + $groups = array_fill_keys( $groups, true ); $this->global_groups = array_merge( $this->global_groups, $groups ); }