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
This commit is contained in:
spacedmonkey 2024-02-13 08:54:11 +00:00
parent a843b188f8
commit 9e92ed15bd
5 changed files with 11 additions and 6 deletions

View File

@ -1974,7 +1974,7 @@ final class WP_Theme implements ArrayAccess {
if ( ! $this->exists() ) { if ( ! $this->exists() ) {
return false; 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' ) ) { if ( is_array( $pattern_data ) && $pattern_data['version'] === $this->get( 'Version' ) ) {
return $pattern_data['patterns']; return $pattern_data['patterns'];
} }
@ -1993,7 +1993,7 @@ final class WP_Theme implements ArrayAccess {
'version' => $this->get( 'Version' ), 'version' => $this->get( 'Version' ),
'patterns' => $patterns, '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 * @since 6.4.0
*/ */
public function delete_pattern_cache() { public function delete_pattern_cache() {
wp_cache_delete( 'wp_theme_patterns_' . $this->stylesheet ); wp_cache_delete( 'wp_theme_patterns_' . $this->stylesheet, 'theme_files' );
} }
/** /**

View File

@ -875,6 +875,7 @@ function wp_start_object_cache() {
'site-options', 'site-options',
'site-queries', 'site-queries',
'site-transient', 'site-transient',
'theme_files',
'rss', 'rss',
'users', 'users',
'user-queries', 'user-queries',

View File

@ -565,6 +565,7 @@ function switch_to_blog( $new_blog_id, $deprecated = null ) {
'site-options', 'site-options',
'site-queries', 'site-queries',
'site-transient', 'site-transient',
'theme_files',
'rss', 'rss',
'users', 'users',
'user-queries', 'user-queries',
@ -658,6 +659,7 @@ function restore_current_blog() {
'site-options', 'site-options',
'site-queries', 'site-queries',
'site-transient', 'site-transient',
'theme_files',
'rss', 'rss',
'users', 'users',
'user-queries', 'user-queries',

View File

@ -837,8 +837,10 @@ function switch_theme( $stylesheet ) {
update_option( 'theme_switched', $old_theme->get_stylesheet() ); update_option( 'theme_switched', $old_theme->get_stylesheet() );
// Clear pattern caches. // Clear pattern caches.
if ( ! is_multisite() ) {
$new_theme->delete_pattern_cache(); $new_theme->delete_pattern_cache();
$old_theme->delete_pattern_cache(); $old_theme->delete_pattern_cache();
}
// Set autoload=no for the old theme, autoload=yes for the switched theme. // Set autoload=no for the old theme, autoload=yes for the switched theme.
$theme_mods_options = array( $theme_mods_options = array(

View File

@ -16,7 +16,7 @@
* *
* @global string $wp_version * @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. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.