Automattic\WooCommerce\Internal\Caches

ProductCacheController::invalidate_product_cache_on_cleanpublicWC 10.5.0

Invalidate the product cache when the post cache is cleaned.

Method of the class: ProductCacheController{}

No Hooks.

Returns

null. Nothing (null).

Usage

$ProductCacheController = new ProductCacheController();
$ProductCacheController->invalidate_product_cache_on_clean( $post_id, $post ): void;
$post_id(int) (required)
The post ID.
$post(WP_Post) (required)
The post object.

Changelog

Since 10.5.0 Introduced.

ProductCacheController::invalidate_product_cache_on_clean() code WC 10.8.1

public function invalidate_product_cache_on_clean( $post_id, $post ): void {
	$post_id = (int) $post_id;
	/**
	 * It's important not to trigger get_post() during this callback as some extensions may attempt to clean cache
	 * prior to updating the database and a call to get_post() would cause the post to be added back to cache before the update.
	 */
	if ( ! ( $post instanceof \WP_Post ) || ! in_array( $post->post_type, array( 'product', 'product_variation' ), true ) ) {
		return;
	}

	$this->product_cache->remove( $post_id );
}