Title: clean_dirsize_cache
Published: December 9, 2020
Last modified: February 24, 2026

---

# clean_dirsize_cache( string $path )

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/clean_dirsize_cache/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/functions/clean_dirsize_cache/?output_format=md#parameters)
 * [Source](https://developer.wordpress.org/reference/functions/clean_dirsize_cache/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/clean_dirsize_cache/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/clean_dirsize_cache/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/functions/clean_dirsize_cache/?output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/functions/clean_dirsize_cache/?output_format=md#wp--skip-link--target)

Cleans directory size cache used by [recurse_dirsize()](https://developer.wordpress.org/reference/functions/recurse_dirsize/).

## 󠀁[Description](https://developer.wordpress.org/reference/functions/clean_dirsize_cache/?output_format=md#description)󠁿

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

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/clean_dirsize_cache/?output_format=md#parameters)󠁿

 `$path`stringrequired

Full path of a directory or file.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/clean_dirsize_cache/?output_format=md#source)󠁿

    ```php
    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 );
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/functions.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/functions.php#L8874)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/functions.php#L8874-L8920)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/clean_dirsize_cache/?output_format=md#related)󠁿

| Uses | Description | 
| [wp_trigger_error()](https://developer.wordpress.org/reference/functions/wp_trigger_error/)`wp-includes/functions.php` |

Generates a user-level error/warning/notice/deprecation message.

  | 
| [untrailingslashit()](https://developer.wordpress.org/reference/functions/untrailingslashit/)`wp-includes/formatting.php` |

Removes trailing forward slashes and backslashes if they exist.

  | 
| [wp_using_ext_object_cache()](https://developer.wordpress.org/reference/functions/wp_using_ext_object_cache/)`wp-includes/load.php` |

Toggles `$_wp_using_ext_object_cache` on and off without directly touching global.

  | 
| [get_transient()](https://developer.wordpress.org/reference/functions/get_transient/)`wp-includes/option.php` |

Retrieves the value of a transient.

  | 
| [set_transient()](https://developer.wordpress.org/reference/functions/set_transient/)`wp-includes/option.php` |

Sets/updates the value of a transient.

  | 
| [__()](https://developer.wordpress.org/reference/functions/__/)`wp-includes/l10n.php` |

Retrieves the translation of $text.

  |

[Show 1 more](https://developer.wordpress.org/reference/functions/clean_dirsize_cache/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/clean_dirsize_cache/?output_format=md#)

| Used by | Description | 
| [_wp_handle_upload()](https://developer.wordpress.org/reference/functions/_wp_handle_upload/)`wp-admin/includes/file.php` |

Handles PHP uploads in WordPress.

  | 
| [wp_upload_bits()](https://developer.wordpress.org/reference/functions/wp_upload_bits/)`wp-includes/functions.php` |

Creates a file in the upload folder with given content.

  | 
| [wp_delete_attachment()](https://developer.wordpress.org/reference/functions/wp_delete_attachment/)`wp-includes/post.php` |

Trashes or deletes an attachment.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/clean_dirsize_cache/?output_format=md#changelog)󠁿

| Version | Description | 
| [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Added input validation with a notice for invalid input. | 
| [5.6.0](https://developer.wordpress.org/reference/since/5.6.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/functions/clean_dirsize_cache/?output_format=md#user-contributed-notes)󠁿

 1.  [Skip to note 2 content](https://developer.wordpress.org/reference/functions/clean_dirsize_cache/?output_format=md#comment-content-4743)
 2.   [cln.lgr](https://profiles.wordpress.org/clnlgrgmailcom/)  [  5 years ago  ](https://developer.wordpress.org/reference/functions/clean_dirsize_cache/#comment-4743)
 3. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fclean_dirsize_cache%2F%23comment-4743)
    Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fclean_dirsize_cache%2F%23comment-4743)
 4. [https://wordpress.org/support/topic/iis-wordpress-5-6-multi-sites-file-upload-hang/](https://wordpress.org/support/topic/iis-wordpress-5-6-multi-sites-file-upload-hang/)
 5.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fclean_dirsize_cache%2F%3Freplytocom%3D4743%23feedback-editor-4743)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fclean_dirsize_cache%2F)
before being able to contribute a note or feedback.