clean_comment_cache()WP 2.3.0

Deletes the object cache of the specified comment.

Will not work if $_wp_suspend_cache_invalidation is not empty. See: wp_suspend_cache_invalidation().

The post cache can be cleared using the function clean_post_cache().

Hooks from the function

Returns

null. Nothing.

Usage

clean_comment_cache( $ids );
$ids(int/array) (required)
The ID of the comment whose cache needs to be deleted. An array of multiple IDs can be specified.

Examples

0

#1 Clear cache posts

Let's say we're editing comment 25 and we need to clear its cache:

clean_comment_cache( 25 );

Let's clear the cache of comments 25 and 34:

clean_comment_cache( [ 25, 34 ] );

Changelog

Since 2.3.0 Introduced.

clean_comment_cache() code WP 6.9

function clean_comment_cache( $ids ) {
	$comment_ids = (array) $ids;
	wp_cache_delete_multiple( $comment_ids, 'comment' );
	foreach ( $comment_ids as $id ) {
		/**
		 * Fires immediately after a comment has been removed from the object cache.
		 *
		 * @since 4.5.0
		 *
		 * @param int $id Comment ID.
		 */
		do_action( 'clean_comment_cache', $id );
	}

	wp_cache_set_comments_last_changed();
}