Make WordPress Core

Changeset 55185


Ignore:
Timestamp:
02/01/2023 10:57:04 PM (23 months ago)
Author:
flixos90
Message:

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.

Location:
trunk
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/global-styles-and-settings.php

    r55155 r55185  
    234234 */
    235235function wp_get_global_styles_svg_filters() {
    236     // Return cached value if it can be used and exists.
    237     // It's cached by theme to make sure that theme switching clears the cache.
    238     $can_use_cached = (
    239         ( ! defined( 'WP_DEBUG' ) || ! WP_DEBUG ) &&
    240         ( ! defined( 'SCRIPT_DEBUG' ) || ! SCRIPT_DEBUG ) &&
    241         ( ! defined( 'REST_REQUEST' ) || ! REST_REQUEST ) &&
    242         ! is_admin()
    243     );
    244     $transient_name = 'global_styles_svg_filters_' . get_stylesheet();
    245     if ( $can_use_cached ) {
    246         $cached = get_transient( $transient_name );
     236    /*
     237     * Ignore cache when `WP_DEBUG` is enabled, so it doesn't interfere with the theme
     238     * developer's workflow.
     239     *
     240     * @todo Replace `WP_DEBUG` once an "in development mode" check is available in Core.
     241     */
     242    $can_use_cached = ! WP_DEBUG;
     243    $cache_group    = 'theme_json';
     244    $cache_key      = 'wp_get_global_styles_svg_filters';
     245    if ( $can_use_cached ) {
     246        $cached = wp_cache_get( $cache_key, $cache_group );
    247247        if ( $cached ) {
    248248            return $cached;
     
    261261
    262262    if ( $can_use_cached ) {
    263         // Cache for a minute, same as wp_get_global_stylesheet.
    264         set_transient( $transient_name, $svgs, MINUTE_IN_SECONDS );
     263        wp_cache_set( $cache_key, $svgs, $cache_group );
    265264    }
    266265
     
    368367function wp_clean_theme_json_cache() {
    369368    wp_cache_delete( 'wp_get_global_stylesheet', 'theme_json' );
     369    wp_cache_delete( 'wp_get_global_styles_svg_filters', 'theme_json' );
    370370    wp_cache_delete( 'wp_get_global_settings_custom', 'theme_json' );
    371371    wp_cache_delete( 'wp_get_global_settings_theme', 'theme_json' );
Note: See TracChangeset for help on using the changeset viewer.