clean_blog_cache( WP_Site|int $blog )
- Since
- 3.5.0
- Source
wp-includes/ms-site.php:959
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
- Scaling
- Constant
- Instructions
- 5–76
- Plugin surface
- 2 hooks
- Called by
- 8
Only touches the object cache, via wp_cache_delete().
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 79.
Third-party callbacks on 'clean_site_cache', 'refresh_blog_details' run inside this call, and their cost is not bounded by anything here.
8 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- cacheobject cache
wp_cache_delete()called directly - hookthird-party callbacks
do_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.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 5–7 | none |
empty($_wp_suspend_cache_invalidation) && !empty($blog) && !$blog_id | 15 | get_site() |
empty($_wp_suspend_cache_invalidation) && !empty($blog) | 66 | get_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_id | 76 | get_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
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 79 | 5–76 | 4 | |
| 8.5 | 79 | 5–76 | 4 | |
| 8.4 | 79 | 5–76 | 4 | 2 fewer instructions than PHP 8.3 |
| 8.3 | 81 | 5–78 | 4 | |
| 8.2 | 81 | 5–78 | 4 | |
| 8.1 | 81 | 5–78 | 4 | |
| 7.4 | 81 | 5–78 | 4 |
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:
- do_action( clean_site_cache )actionline 1007 (+48 into the body)
Fires immediately after a site has been removed from the object cache.
- do_action( refresh_blog_details )action_deprecatedline 1019 (+60 into the body)
Fires after the blog details cache is cleared.
Uses · 6
- get_site()Retrieves site data given a site ID or site object.
- wp_cache_delete()Removes the cache contents matching key and group.
- do_action()Calls the callback functions that have been added to an action hook.
- wp_cache_set_sites_last_changed()Sets the last changed time for the 'sites' cache group.
- do_action_deprecated()Fires functions attached to a deprecated action hook.
- WP_Site::__construct()Creates a new WP_Site object.
Used by · 8
- insert_blog()Store basic site info in the blogs table.
- refresh_blog_details()Clears the blog details cache.
- upgrade_280()Execute changes made in WordPress 2.8.
- wp_delete_site()Deletes a site from the database.
- wp_initialize_site()Runs the initialization routine for a given site.
- wp_insert_site()Inserts a new site into the database.
- wp_maybe_clean_new_site_cache_on_update()Cleans the necessary caches after specific site data has been updated.
- wp_update_site()Updates a site in the database.
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.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 6.9.7 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.