ActionScheduler_QueueRunner::clear_caches()protectedWC 1.0

Flush the cache if possible (intended for use after a batch of actions has been processed).

This is useful because running large batches can eat up memory and because invalid data can accrue in the runtime cache, which may lead to unexpected results.

Method of the class: ActionScheduler_QueueRunner{}

Return

null. Nothing (null).

Usage

// protected - for code of main (parent) or child class
$result = $this->clear_caches();

ActionScheduler_QueueRunner::clear_caches() code WC 8.7.0

protected function clear_caches() {
	/*
	 * Calling wp_cache_flush_runtime() lets us clear the runtime cache without invalidating the external object
	 * cache, so we will always prefer this method (as compared to calling wp_cache_flush()) when it is available.
	 *
	 * However, this function was only introduced in WordPress 6.0. Additionally, the preferred way of detecting if
	 * it is supported changed in WordPress 6.1 so we use two different methods to decide if we should utilize it.
	 */
	$flushing_runtime_cache_explicitly_supported = function_exists( 'wp_cache_supports' ) && wp_cache_supports( 'flush_runtime' );
	$flushing_runtime_cache_implicitly_supported = ! function_exists( 'wp_cache_supports' ) && function_exists( 'wp_cache_flush_runtime' );

	if ( $flushing_runtime_cache_explicitly_supported || $flushing_runtime_cache_implicitly_supported ) {
		wp_cache_flush_runtime();
	} elseif (
		! wp_using_ext_object_cache()
		/**
		 * When an external object cache is in use, and when wp_cache_flush_runtime() is not available, then
		 * normally the cache will not be flushed after processing a batch of actions (to avoid a performance
		 * penalty for other processes).
		 *
		 * This filter makes it possible to override this behavior and always flush the cache, even if an external
		 * object cache is in use.
		 *
		 * @since 1.0
		 *
		 * @param bool $flush_cache If the cache should be flushed.
		 */
		|| apply_filters( 'action_scheduler_queue_runner_flush_cache', false )
	) {
		wp_cache_flush();
	}
}