WC_Post_Data::invalidate_products_last_modifiedpublic staticWC 10.6.0

Invalidate the cached products last modified timestamp when a product post cache is cleaned.

This does not use wp_cache_set_last_changed() because the cached value is exposed to clients via the Last-Modified HTTP header for collection cache invalidation. WordPress core's last_changed pattern auto-seeds with the current time on cache miss, which is acceptable for opaque cache-key salts but would force all clients to unnecessarily invalidate their local caches. Instead, invalidating the cache here allows the read side in ProductQuery::get_last_modified() to fall back to the DB and re-seed with the real last modification time.

Method of the class: WC_Post_Data{}

No Hooks.

Returns

null. Nothing (null).

Usage

$result = WC_Post_Data::invalidate_products_last_modified( $post_id, $post ): void;
$post_id(int) (required)
Post ID.
$post(WP_Post) (required)
Post object.

Changelog

Since 10.6.0 Introduced.

WC_Post_Data::invalidate_products_last_modified() code WC 10.8.1

public static function invalidate_products_last_modified( $post_id, $post ): void {
	if ( $post instanceof WP_Post && in_array( $post->post_type, array( 'product', 'product_variation' ), true ) ) {
		wp_cache_delete( 'last_modified', 'wc_products' );
	}
}