wp_cache_flush_runtime()WP 6.0.0

Completely clears the object cache only if it is stored in memory (persistent caching is not used). With persistent caching, it does nothing.

As discussed in ticket #55080, WP needed a way for users to clear the object cache in memory while not touching the cache if it is stored persistently (not in memory), for example, in Redis - read more about Persistent Object Cache.

This capability has often been needed for cases where long-running processes are initiated in cron jobs or via WP-CLI.

No Hooks.

Returns

true|false. True on success, false on failure.

Usage

wp_cache_flush_runtime();

Examples

0

#1 Example of use

In the example below, the object cache will be flushed after 100 posts have been added to the database:

$counter = 0;

foreach ( $posts as $post ) {
	$counter++;

	wp_insert_post( $post );

	if ( 100 === $counter ) {
		wp_cache_flush_runtime();
		$counter = 0;
	} 

}

Notes

Changelog

Since 6.0.0 Introduced.

wp_cache_flush_runtime() code WP 6.8.1

function wp_cache_flush_runtime() {
	return wp_cache_flush();
}