From 314316a7344335f5644a777fecbae2f4a67d72d0 Mon Sep 17 00:00:00 2001 From: Jonny Harrus Date: Thu, 23 Jan 2025 12:36:47 -0500 Subject: [PATCH] Refactor alloptions cache handling for non-external caches Introduce separate logic for handling alloptions when not using an external object cache. This includes retrieving keys and setting multiple cache entries individually, improving compatibility and efficiency for internal caching mechanisms. --- src/wp-includes/option.php | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/option.php b/src/wp-includes/option.php index 4b26504b76356..79b44caff10b1 100644 --- a/src/wp-includes/option.php +++ b/src/wp-includes/option.php @@ -618,7 +618,15 @@ function wp_load_alloptions( $force_cache = false ) { } if ( ! wp_installing() || ! is_multisite() ) { - $alloptions = wp_cache_get( 'alloptions', 'options', $force_cache ); + if ( wp_using_ext_object_cache() ) { + $alloptions = wp_cache_get( 'alloptions', 'options', $force_cache ); + } else { + $alloptionskeys = wp_cache_get( 'alloptionskeys', 'options', $force_cache ); + $alloptions = false; + if ( is_array( $alloptionskeys ) ) { + $alloptions = wp_cache_get_multiple( $alloptionskeys, 'options' ); + } + } } else { $alloptions = false; } @@ -647,7 +655,12 @@ function wp_load_alloptions( $force_cache = false ) { */ $alloptions = apply_filters( 'pre_cache_alloptions', $alloptions ); - wp_cache_add( 'alloptions', $alloptions, 'options' ); + if ( wp_using_ext_object_cache() ) { + wp_cache_add( 'alloptions', $alloptions, 'options' ); + } else { + wp_cache_set_multiple( $alloptions, '', 'options' ); + wp_cache_set( 'alloptionskeys', array_keys( $alloptions ), 'options' ); + } } }