Automattic\WooCommerce\Internal\Caches

ProductTermCacheInvalidator{} │ WC 11.2.0

Invalidates cached product terms when taxonomy caches are cleaned.

No Hooks.

Usage

$ProductTermCacheInvalidator = new ProductTermCacheInvalidator();
// use class methods

Methods

  1. public handle_clean_taxonomy_cache( $taxonomy )
  2. public init()

Changelog

Since 11.2.0 Introduced.

ProductTermCacheInvalidator{} code WC 11.2.1

class ProductTermCacheInvalidator {
	/**
	 * Register cache invalidation hooks.
	 *
	 * @since 11.2.0
	 *
	 * @internal
	 */
	final public function init(): void {
		add_action( 'clean_taxonomy_cache', array( $this, 'handle_clean_taxonomy_cache' ) );
	}

	/**
	 * Invalidate cached product terms after a taxonomy cache is cleaned.
	 *
	 * @since 11.2.0
	 *
	 * @internal
	 *
	 * @param mixed $taxonomy Taxonomy name.
	 */
	public function handle_clean_taxonomy_cache( $taxonomy ): void {
		if ( ! is_string( $taxonomy ) || ! is_object_in_taxonomy( 'product', $taxonomy ) ) {
			return;
		}

		WC_Cache_Helper::invalidate_cache_group( 'product_terms_' . $taxonomy );
	}
}