Editor: Use a non-persistent object cache instead of transient in wp_get_global_stylesheet().

This changeset is part of a greater effort to enhance the caching strategy for theme.json based data. Similar to [55138], [55148], and [55155], the cache is currently ignored when `WP_DEBUG` is on to avoid interrupting the theme developer's workflow.

Props spacedmonkey, oandregal, flixos90, ajlende, hellofromtonya.
Fixes #57568.

Built from https://develop.svn.wordpress.org/trunk@55185


git-svn-id: http://core.svn.wordpress.org/trunk@54718 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Felix Arntz 2023-02-01 22:59:13 +00:00
parent 1056e0175c
commit 9feba5fa8b
2 changed files with 13 additions and 13 deletions

View File

@ -233,17 +233,17 @@ function wp_get_global_stylesheet( $types = array() ) {
* @return string * @return string
*/ */
function wp_get_global_styles_svg_filters() { function wp_get_global_styles_svg_filters() {
// Return cached value if it can be used and exists. /*
// It's cached by theme to make sure that theme switching clears the cache. * Ignore cache when `WP_DEBUG` is enabled, so it doesn't interfere with the theme
$can_use_cached = ( * developer's workflow.
( ! defined( 'WP_DEBUG' ) || ! WP_DEBUG ) && *
( ! defined( 'SCRIPT_DEBUG' ) || ! SCRIPT_DEBUG ) && * @todo Replace `WP_DEBUG` once an "in development mode" check is available in Core.
( ! defined( 'REST_REQUEST' ) || ! REST_REQUEST ) && */
! is_admin() $can_use_cached = ! WP_DEBUG;
); $cache_group = 'theme_json';
$transient_name = 'global_styles_svg_filters_' . get_stylesheet(); $cache_key = 'wp_get_global_styles_svg_filters';
if ( $can_use_cached ) { if ( $can_use_cached ) {
$cached = get_transient( $transient_name ); $cached = wp_cache_get( $cache_key, $cache_group );
if ( $cached ) { if ( $cached ) {
return $cached; return $cached;
} }
@ -260,8 +260,7 @@ function wp_get_global_styles_svg_filters() {
$svgs = $tree->get_svg_filters( $origins ); $svgs = $tree->get_svg_filters( $origins );
if ( $can_use_cached ) { if ( $can_use_cached ) {
// Cache for a minute, same as wp_get_global_stylesheet. wp_cache_set( $cache_key, $svgs, $cache_group );
set_transient( $transient_name, $svgs, MINUTE_IN_SECONDS );
} }
return $svgs; return $svgs;
@ -367,6 +366,7 @@ function wp_theme_has_theme_json() {
*/ */
function wp_clean_theme_json_cache() { function wp_clean_theme_json_cache() {
wp_cache_delete( 'wp_get_global_stylesheet', 'theme_json' ); wp_cache_delete( 'wp_get_global_stylesheet', 'theme_json' );
wp_cache_delete( 'wp_get_global_styles_svg_filters', 'theme_json' );
wp_cache_delete( 'wp_get_global_settings_custom', 'theme_json' ); wp_cache_delete( 'wp_get_global_settings_custom', 'theme_json' );
wp_cache_delete( 'wp_get_global_settings_theme', 'theme_json' ); wp_cache_delete( 'wp_get_global_settings_theme', 'theme_json' );
WP_Theme_JSON_Resolver::clean_cached_data(); WP_Theme_JSON_Resolver::clean_cached_data();

View File

@ -16,7 +16,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '6.2-alpha-55184'; $wp_version = '6.2-alpha-55185';
/** /**
* 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.