@@ -85,8 +85,24 @@ function wp_get_global_styles( $path = array(), $context = array() ) {
8585function wp_get_global_stylesheet ( $ types = array () ) {
8686 // Ignore cache when `WP_DEBUG` is enabled, so it doesn't interfere with the theme developers workflow.
8787 $ can_use_cached = empty ( $ types ) && ! WP_DEBUG ;
88- $ cache_key = 'wp_get_global_stylesheet ' ;
88+ /**
89+ * By using the 'theme_json' group, this data is marked to be non-persistent across requests.
90+ * See `wp_cache_add_non_persistent_groups` in src/wp-includes/load.php
91+ *
92+ * The rationale for this is to make sure derived data from theme.json
93+ * is always fresh from the potential modifications done via hooks
94+ * that can use dynamic data (modify the stylesheet depending on some option,
95+ * settings depending on user permissions, etc.).
96+ * See some of the existing hooks to modify theme.json behaviour:
97+ * https://make.wordpress.org/core/2022/10/10/filters-for-theme-json-data/
98+ *
99+ * A different alternative considered was to invalidate the cache upon certain
100+ * events such as options add/update/delete, user meta, etc.
101+ * It was judged not enough, hence this approach.
102+ * See https://github.com/WordPress/gutenberg/pull/45372
103+ */
89104 $ cache_group = 'theme_json ' ;
105+ $ cache_key = 'wp_get_global_stylesheet ' ;
90106 if ( $ can_use_cached ) {
91107 $ cached = wp_cache_get ( $ cache_key , $ cache_group );
92108 if ( $ cached ) {
@@ -253,30 +269,3 @@ function _wp_clean_theme_json_caches() {
253269 wp_cache_delete ( 'wp_get_global_stylesheet ' , 'theme_json ' );
254270 WP_Theme_JSON_Resolver::clean_cached_data ();
255271}
256-
257- /**
258- * Tell the cache mechanisms not to persist theme.json data across requests.
259- * The data stored under this cache group:
260- *
261- * - wp_get_global_stylesheet
262- *
263- * There is some hooks consumers can use to modify parts
264- * of the theme.json logic.
265- * See https://make.wordpress.org/core/2022/10/10/filters-for-theme-json-data/
266- *
267- * The rationale to make this cache group non persistent is to make sure derived data
268- * from theme.json is always fresh from the potential modifications done via hooks
269- * that can use dynamic data (modify the stylesheet depending on some option,
270- * or settings depending on user permissions, etc.).
271- *
272- * A different alternative considered was to invalidate the cache upon certain
273- * events such as options add/update/delete, user meta, etc.
274- * It was judged not enough, hence this approach.
275- * See https://github.com/WordPress/gutenberg/pull/45372
276- *
277- * @since 6.1.2
278- * @access private
279- */
280- function _wp_add_non_persistent_theme_json_cache_group () {
281- wp_cache_add_non_persistent_groups ( 'theme_json ' );
282- }
0 commit comments