wppaste
WordPress

clean_blog_cache( WP_Site|int $blog )

Since
3.5.0
Source
wp-includes/ms-site.php:959
Clean the blog cache

Compatibility

WordPress
since 3.5.0
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.

Parameters

$blogWP_Site|int
The site object or ID to be cleared from cache.

Performance profile

How much work a call to clean_blog_cache() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Light

Only touches the object cache, via wp_cache_delete().

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
5–76

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 79.

Plugin surface
2 hooks

Third-party callbacks on 'clean_site_cache', 'refresh_blog_details' run inside this call, and their cost is not bounded by anything here.

Called by
8

8 places in core call this, so the cost is paid more often than your own code shows.

What it touches

  • cacheobject cachewp_cache_delete()called directly
  • hookthird-party callbacksdo_action()called directly

Further down the call graph this can also reach query, option, serialize and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.

What one call costs · 4 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost clean_blog_cache() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
always5–7none
empty($_wp_suspend_cache_invalidation) && !empty($blog) && !$blog_id15get_site()
empty($_wp_suspend_cache_invalidation) && !empty($blog)66get_site(), md5(), wp_cache_delete(), wp_cache_delete(), wp_cache_delete(), wp_cache_delete(), wp_cache_delete(), wp_cache_delete(), wp_cache_delete(), do_action(), wp_cache_set_sites_last_changed()
empty($_wp_suspend_cache_invalidation) && !empty($blog) && $blog_id76get_site(), blog_id(), md5(), wp_cache_delete(), wp_cache_delete(), wp_cache_delete(), wp_cache_delete(), wp_cache_delete(), wp_cache_delete(), wp_cache_delete(), do_action(), wp_cache_set_sites_last_changed()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev795–764
8.5795–764
8.4795–7642 fewer instructions than PHP 8.3
8.3815–784
8.2815–784
8.1815–784
7.4815–784

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Hooks and filters fired · 2

2 hooks fire while clean_blog_cache() runs, in this order:

  1. do_action( clean_site_cache )actionline 1007 (+48 into the body)

    Fires immediately after a site has been removed from the object cache.

  2. do_action( refresh_blog_details )action_deprecatedline 1019 (+60 into the body)

    Fires after the blog details cache is cleared.

Uses · 6

Used by · 8

Source code

function clean_blog_cache( $blog ) {	global $_wp_suspend_cache_invalidation; 	if ( ! empty( $_wp_suspend_cache_invalidation ) ) {		return;	} 	if ( empty( $blog ) ) {		return;	} 	$blog_id = $blog;	$blog    = get_site( $blog_id );	if ( ! $blog ) {		if ( ! is_numeric( $blog_id ) ) {			return;		} 		// Make sure a WP_Site object exists even when the site has been deleted.		$blog = new WP_Site(			(object) array(				'blog_id' => $blog_id,				'domain'  => null,				'path'    => null,			)		);	} 	$blog_id         = $blog->blog_id;	$domain_path_key = md5( $blog->domain . $blog->path ); 	wp_cache_delete( $blog_id, 'sites' );	wp_cache_delete( $blog_id, 'site-details' );	wp_cache_delete( $blog_id, 'blog-details' );	wp_cache_delete( $blog_id . 'short', 'blog-details' );	wp_cache_delete( $domain_path_key, 'blog-lookup' );	wp_cache_delete( $domain_path_key, 'blog-id-cache' );	wp_cache_delete( $blog_id, 'blog_meta' ); 	/**	 * Fires immediately after a site has been removed from the object cache.	 *	 * @since 4.6.0	 *	 * @param string  $id              Site ID as a numeric string.	 * @param WP_Site $blog            Site object.	 * @param string  $domain_path_key md5 hash of domain and path.	 */	do_action( 'clean_site_cache', $blog_id, $blog, $domain_path_key ); 	wp_cache_set_sites_last_changed(); 	/**	 * Fires after the blog details cache is cleared.	 *	 * @since 3.4.0	 * @deprecated 4.9.0 Use {@see 'clean_site_cache'} instead.	 *	 * @param int $blog_id Blog ID.	 */	do_action_deprecated( 'refresh_blog_details', array( $blog_id ), '4.9.0', 'clean_site_cache' );}

Changelog

Introduced in 3.5.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-includes/ms-site.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.