WordPress.org

Make WordPress Core

Ticket #40028: 40028.2.diff

File 40028.2.diff, 2.9 KB (added by jeremyfelt, 2 years ago)
  • src/wp-includes/ms-blogs.php

     
    446446 * @param WP_Site $blog The site object to be cleared from cache.
    447447 */
    448448function clean_blog_cache( $blog ) {
     449        global $_wp_suspend_cache_invalidation;
     450
     451        if ( ! empty( $_wp_suspend_cache_invalidation ) ) {
     452                return;
     453        }
     454
    449455        $blog_id = $blog->blog_id;
    450456        $domain_path_key = md5( $blog->domain . $blog->path );
    451457
    452458        wp_cache_delete( $blog_id, 'sites' );
    453459        wp_cache_delete( $blog_id, 'site-details' );
    454         wp_cache_delete( $blog_id , 'blog-details' );
     460        wp_cache_delete( $blog_id, 'blog-details' );
    455461        wp_cache_delete( $blog_id . 'short' , 'blog-details' );
    456         wp_cache_delete(  $domain_path_key, 'blog-lookup' );
     462        wp_cache_delete( $domain_path_key, 'blog-lookup' );
     463        wp_cache_delete( $domain_path_key, 'blog-id-cache' );
    457464        wp_cache_delete( 'current_blog_' . $blog->domain, 'site-options' );
    458465        wp_cache_delete( 'current_blog_' . $blog->domain . $blog->path, 'site-options' );
    459         wp_cache_delete( $domain_path_key, 'blog-id-cache' );
    460466
    461467        /**
    462468         * Fires immediately after a site has been removed from the object cache.
     
    11521158 * @param int|array $ids Network ID or an array of network IDs to remove from cache.
    11531159 */
    11541160function clean_network_cache( $ids ) {
     1161        global $_wp_suspend_cache_invalidation;
     1162
     1163        if ( ! empty( $_wp_suspend_cache_invalidation ) ) {
     1164                return;
     1165        }
     1166
    11551167        foreach ( (array) $ids as $id ) {
    11561168                wp_cache_delete( $id, 'networks' );
    11571169
  • tests/phpunit/tests/multisite/site.php

     
    122122                $this->assertEquals( 2, (int) get_blog_count() );
    123123        }
    124124
     125        public function test_site_caches_should_invalidate_when_invalidation_is_not_suspended() {
     126                $site_id = self::factory()->blog->create();
     127
     128                $details = get_site( $site_id );
     129
     130                $suspend = wp_suspend_cache_invalidation( false );
     131                update_blog_details( $site_id, array( 'path' => '/a-non-random-test-path/' ) );
     132                $new_details = get_site( $site_id );
     133                wp_suspend_cache_invalidation( $suspend );
     134
     135                $this->assertNotEquals( $details->path, $new_details->path );
     136        }
     137
     138        public function test_invalidating_site_caches_should_fail_when_invalidation_is_suspended() {
     139                $site_id = self::factory()->blog->create();
     140
     141                $details = get_site( $site_id );
     142
     143                $suspend = wp_suspend_cache_invalidation();
     144                update_blog_details( $site_id, array( 'path' => '/a-non-random-test-path/' ) );
     145                $new_details = get_site( $site_id );
     146                wp_suspend_cache_invalidation( $suspend );
     147
     148                $this->assertEquals( $details->path, $new_details->path );
     149        }
     150
    125151        /**
    126152         * When a site is flagged as 'deleted', its data should be cleared from cache.
    127153         */