Skip to content

Commit b8415be

Browse files
oandregalmpkelly
authored andcommitted
Implement object cache for gutenberg_get_global_settings (WordPress#45372)
1 parent 020c67b commit b8415be

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

lib/compat/wordpress-6.2/get-global-styles-and-settings.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,15 @@ function gutenberg_get_global_settings( $path = array(), $context = array() ) {
171171
$origin = 'theme';
172172
}
173173

174-
$settings = WP_Theme_JSON_Resolver_Gutenberg::get_merged_data( $origin )->get_settings();
174+
$cache_group = 'theme_json';
175+
$cache_key = 'gutenberg_get_global_settings_' . $origin;
176+
$settings = wp_cache_get( $cache_key, $cache_group );
177+
178+
if ( false === $settings || WP_DEBUG ) {
179+
$settings = WP_Theme_JSON_Resolver_Gutenberg::get_merged_data( $origin )->get_settings();
180+
wp_cache_set( $cache_key, $settings, $cache_group );
181+
}
182+
175183
return _wp_array_get( $settings, $path, $settings );
176184
}
177185

@@ -183,6 +191,7 @@ function gutenberg_get_global_settings( $path = array(), $context = array() ) {
183191
function _gutenberg_clean_theme_json_caches() {
184192
wp_cache_delete( 'wp_theme_has_theme_json', 'theme_json' );
185193
wp_cache_delete( 'gutenberg_get_global_stylesheet', 'theme_json' );
194+
wp_cache_delete( 'gutenberg_get_global_settings_custom', 'theme_json' );
186195
wp_cache_delete( 'gutenberg_get_global_settings_theme', 'theme_json' );
187196
WP_Theme_JSON_Resolver_Gutenberg::clean_cached_data();
188197
}
@@ -192,6 +201,7 @@ function _gutenberg_clean_theme_json_caches() {
192201
* The data stored under this cache group:
193202
*
194203
* - wp_theme_has_theme_json
204+
* - gutenberg_get_global_settings
195205
* - gutenberg_get_global_stylesheet
196206
*
197207
* There is some hooks consumers can use to modify parts

0 commit comments

Comments
 (0)