Skip to content

Commit

Permalink
Revamp cache invalidation.
Browse files Browse the repository at this point in the history
  • Loading branch information
spacedmonkey committed Dec 13, 2022
1 parent b5c2eec commit 567f818
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 26 deletions.
2 changes: 0 additions & 2 deletions lib/compat/wordpress-6.2/default-filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
* @package gutenberg
*/

add_action( 'delete_theme', 'wp_theme_has_theme_json_clean_cache' );
add_action( 'upgrader_process_complete', '_wp_theme_has_theme_json_clean_cache_upon_upgrading_active_theme', 10, 2 );
/**
* When backporting to core, the existing filters hooked to WP_Theme_JSON_Resolver::clean_cached_data()
* need to be removed.
Expand Down
30 changes: 6 additions & 24 deletions lib/compat/wordpress-6.2/get-global-styles-and-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,29 +66,6 @@ function wp_theme_has_theme_json_clean_cache( $stylesheet = '' ) {
}
}

if ( ! function_exists( '_wp_theme_has_theme_json_clean_cache_upon_upgrading_active_theme' ) ) {
/**
* Private function to clean the cache used by wp_theme_has_theme_json method.
*
* It is hooked into the `upgrader_process_complete` action.
*
* @param WP_Upgrader $upgrader Instance of WP_Upgrader class.
* @param array $options Metadata that identifies the data that is updated.
*
* @see default-filters.php
*
*/
function _wp_theme_has_theme_json_clean_cache_upon_upgrading_active_theme( $upgrader, $options ) {
// The cache only needs cleaning when the active theme was updated.
if ( 'update' === $options['action'] && 'theme' === $options['type'] && ! empty( $options['themes'] ) ) {
foreach ( $options['themes'] as $theme ) {
wp_theme_has_theme_json_clean_cache( $theme );
}
}

}
}

/**
* Returns the stylesheet resulting of merging core, theme, and user data.
*
Expand Down Expand Up @@ -219,7 +196,12 @@ function gutenberg_get_global_settings( $path = array(), $context = array() ) {
* @access private
*/
function _gutenberg_clean_theme_json_caches() {
wp_cache_delete( 'wp_theme_has_theme_json', 'theme_json' );
$stylesheet = get_stylesheet();
$template = get_template();
wp_theme_has_theme_json_clean_cache( $stylesheet );
if( $stylesheet !== $template ){
wp_theme_has_theme_json_clean_cache( $template );
}
wp_cache_delete( 'gutenberg_get_global_stylesheet', 'theme_json' );
wp_cache_delete( 'gutenberg_get_global_settings_custom', 'theme_json' );
wp_cache_delete( 'gutenberg_get_global_settings_theme', 'theme_json' );
Expand Down

0 comments on commit 567f818

Please sign in to comment.