wppaste
WordPress

clean_dirsize_cache( string $path )

Since
5.6.0, 5.9.0
Source
wp-includes/functions.php:9044
Cleans directory size cache used by recurse_dirsize().

Description

Removes the current directory and all parent directories from the dirsize_cache transient.

Compatibility

WordPress
since 5.9.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

$pathstring
Full path of a directory or file.

Performance profile

How much work a call to clean_dirsize_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
Heavy

Reads stored settings via get_option(), cached per request but not free on a cold cache.

Scaling
Scales with input

The body loops, so the work grows with what you pass in.

Instructions
12–42

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

Plugin surface
None

Nothing here hands control to plugin code.

Called by
3

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

What it touches

  • transienttransientget_transient()called directly
  • hookthird-party callbacksdo_action()one call below clean_dirsize_cache()
  • cacheobject cachewp_cache_get()one call below clean_dirsize_cache()
  • optionoption read or writeget_option()one call below clean_dirsize_cache()

Further down the call graph this can also reach serialize and query. 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_dirsize_cache() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
is_string($path) && !empty($path) && empty($directory_cache)12get_transient()
always19–21__(), sprintf(), wp_trigger_error()
is_string($path) && !empty($path) && !empty($directory_cache) && !$path28get_transient(), wp_using_ext_object_cache(), set_transient()
is_string($path) && !empty($path) && !empty($directory_cache) && $path34–42get_transient(), wp_using_ext_object_cache(), untrailingslashit(), set_transient()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev7212–4210
8.57212–4210
8.47212–42108 fewer instructions than PHP 8.3
8.38012–4810
8.28012–4810
8.18012–48101 fewer instruction than PHP 7.4
7.48112–4910

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.

Uses · 7

Used by · 3

Source code

function clean_dirsize_cache( $path ) {	if ( ! is_string( $path ) || empty( $path ) ) {		wp_trigger_error(			'',			sprintf(				/* translators: 1: Function name, 2: A variable type, like "boolean" or "integer". */				__( '%1$s only accepts a non-empty path string, received %2$s.' ),				'<code>clean_dirsize_cache()</code>',				'<code>' . gettype( $path ) . '</code>'			)		);		return;	} 	$directory_cache = get_transient( 'dirsize_cache' ); 	if ( empty( $directory_cache ) ) {		return;	} 	$expiration = ( wp_using_ext_object_cache() ) ? 0 : 10 * YEAR_IN_SECONDS;	if (		! str_contains( $path, '/' ) &&		! str_contains( $path, '\\' )	) {		unset( $directory_cache[ $path ] );		set_transient( 'dirsize_cache', $directory_cache, $expiration );		return;	} 	$last_path = null;	$path      = untrailingslashit( $path );	unset( $directory_cache[ $path ] ); 	while (		$last_path !== $path &&		DIRECTORY_SEPARATOR !== $path &&		'.' !== $path &&		'..' !== $path	) {		$last_path = $path;		$path      = dirname( $path );		unset( $directory_cache[ $path ] );	} 	set_transient( 'dirsize_cache', $directory_cache, $expiration );}

Changelog

Introduced in 5.6.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.

5.9.0
Added input validation with a notice for invalid input.from the docblock
5.6.0
Introduced.from the docblock

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-includes/functions.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.