From 9e92ed15bd6f26b4bd87828320104ea99a01cfd2 Mon Sep 17 00:00:00 2001 From: spacedmonkey Date: Tue, 13 Feb 2024 08:54:11 +0000 Subject: [PATCH] Themes: Add 'theme_files' cache group to block pattern cache operations. Use 'theme_files' cache group for block pattern caches. Previously, block pattern cache data was not stored in a cache group and used the default group. This new cache group, is setup as a global cache group, meaning that sites using multisite, will have a single cache for block pattern data per theme. This change also no longer invalidate block pattern caches in multisite instances, meaning block pattern caches can be shared between sites on a network, meaning less repeated data in the object cache. Props spacedmonkey, flixos90, joemcgill. Fixes #60120. Built from https://develop.svn.wordpress.org/trunk@57608 git-svn-id: http://core.svn.wordpress.org/trunk@57109 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/class-wp-theme.php | 6 +++--- wp-includes/load.php | 1 + wp-includes/ms-blogs.php | 2 ++ wp-includes/theme.php | 6 ++++-- wp-includes/version.php | 2 +- 5 files changed, 11 insertions(+), 6 deletions(-) diff --git a/wp-includes/class-wp-theme.php b/wp-includes/class-wp-theme.php index a664a1ea0b..e6eeb8ca5d 100644 --- a/wp-includes/class-wp-theme.php +++ b/wp-includes/class-wp-theme.php @@ -1974,7 +1974,7 @@ final class WP_Theme implements ArrayAccess { if ( ! $this->exists() ) { return false; } - $pattern_data = wp_cache_get( 'wp_theme_patterns_' . $this->stylesheet ); + $pattern_data = wp_cache_get( 'wp_theme_patterns_' . $this->stylesheet, 'theme_files' ); if ( is_array( $pattern_data ) && $pattern_data['version'] === $this->get( 'Version' ) ) { return $pattern_data['patterns']; } @@ -1993,7 +1993,7 @@ final class WP_Theme implements ArrayAccess { 'version' => $this->get( 'Version' ), 'patterns' => $patterns, ); - wp_cache_set( 'wp_theme_patterns_' . $this->stylesheet, $pattern_data ); + wp_cache_set( 'wp_theme_patterns_' . $this->stylesheet, $pattern_data, 'theme_files' ); } /** @@ -2002,7 +2002,7 @@ final class WP_Theme implements ArrayAccess { * @since 6.4.0 */ public function delete_pattern_cache() { - wp_cache_delete( 'wp_theme_patterns_' . $this->stylesheet ); + wp_cache_delete( 'wp_theme_patterns_' . $this->stylesheet, 'theme_files' ); } /** diff --git a/wp-includes/load.php b/wp-includes/load.php index c188598768..d10aff376f 100644 --- a/wp-includes/load.php +++ b/wp-includes/load.php @@ -875,6 +875,7 @@ function wp_start_object_cache() { 'site-options', 'site-queries', 'site-transient', + 'theme_files', 'rss', 'users', 'user-queries', diff --git a/wp-includes/ms-blogs.php b/wp-includes/ms-blogs.php index 4a251cf300..b9575b3bef 100644 --- a/wp-includes/ms-blogs.php +++ b/wp-includes/ms-blogs.php @@ -565,6 +565,7 @@ function switch_to_blog( $new_blog_id, $deprecated = null ) { 'site-options', 'site-queries', 'site-transient', + 'theme_files', 'rss', 'users', 'user-queries', @@ -658,6 +659,7 @@ function restore_current_blog() { 'site-options', 'site-queries', 'site-transient', + 'theme_files', 'rss', 'users', 'user-queries', diff --git a/wp-includes/theme.php b/wp-includes/theme.php index 0b0df6c7b0..c8cbc60cc6 100644 --- a/wp-includes/theme.php +++ b/wp-includes/theme.php @@ -837,8 +837,10 @@ function switch_theme( $stylesheet ) { update_option( 'theme_switched', $old_theme->get_stylesheet() ); // Clear pattern caches. - $new_theme->delete_pattern_cache(); - $old_theme->delete_pattern_cache(); + if ( ! is_multisite() ) { + $new_theme->delete_pattern_cache(); + $old_theme->delete_pattern_cache(); + } // Set autoload=no for the old theme, autoload=yes for the switched theme. $theme_mods_options = array( diff --git a/wp-includes/version.php b/wp-includes/version.php index 02330a5545..487330710a 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.5-alpha-57607'; +$wp_version = '6.5-alpha-57608'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.