Skip to content

Commit

Permalink
Improve caching.
Browse files Browse the repository at this point in the history
  • Loading branch information
spacedmonkey committed Nov 3, 2022
1 parent 25c75ed commit e99fd77
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions src/wp-includes/global-styles-and-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,18 +261,13 @@ function ( $item ) {
*
* @since 6.2.0
*
* @param boolean $clear_cache Whether the cache should be cleared and theme support recomputed. Default is false.
*
* @return boolean
*/
function wp_theme_has_theme_json( $clear_cache = false ) {
static $theme_has_support = null;

if ( true === $clear_cache ) {
$theme_has_support = null;
}

if ( null !== $theme_has_support ) {
function wp_theme_has_theme_json() {
$cache_key = 'theme_has_support';
$cache_found = false;
$theme_has_support = wp_cache_get( $cache_key, '', false, $cache_found );
if ( $cache_found ) {
return $theme_has_support;
}

Expand All @@ -284,6 +279,8 @@ function wp_theme_has_theme_json( $clear_cache = false ) {
$theme_has_support = is_readable( get_template_directory() . '/theme.json' );
}

wp_cache_set( $cache_key, $theme_has_support );

return $theme_has_support;
}

Expand All @@ -294,6 +291,6 @@ function wp_theme_has_theme_json( $clear_cache = false ) {
*
*/
function wp_theme_clean_theme_json_cached_data() {
wp_theme_has_theme_json( true );
wp_cache_delete( 'theme_has_support' );
WP_Theme_JSON_Resolver::clean_cached_data();
}

0 comments on commit e99fd77

Please sign in to comment.