将清理缓存中的帖子。

原型

clean_post_cache( int|WP_Post $post )

描述

清理意味着从帖子的缓存中删除。将调用以清除与帖子ID关联的术语对象缓存。

参数

$post (int|WP_Post) (Required) 要从缓存中删除的帖子ID或帖子对象。

源文件

路径:wp-includes/post.php

<?php
...
function clean_post_cache( $post ) {
	global $_wp_suspend_cache_invalidation;
	if ( ! empty( $_wp_suspend_cache_invalidation ) )
		return;
	$post = get_post( $post );
	if ( empty( $post ) )
		return;
	wp_cache_delete( $post->ID, 'posts' );
	wp_cache_delete( $post->ID, 'post_meta' );
	clean_object_term_cache( $post->ID, $post->post_type );
	wp_cache_delete( 'wp_get_archives', 'general' );
	/**
	 * Fires immediately after the given post's cache is cleaned.
	 *
	 * @since 2.5.0
	 *
	 * @param int     $post_id Post ID.
	 * @param WP_Post $post    Post object.
	 */
	do_action( 'clean_post_cache', $post->ID, $post );
	if ( 'page' == $post->post_type ) {
		wp_cache_delete( 'all_page_ids', 'posts' );
		/**
		 * Fires immediately after the given page's cache is cleaned.
		 *
		 * @since 2.5.0
		 *
		 * @param int $post_id Post ID.
		 */
		do_action( 'clean_page_cache', $post->ID );
	}
	wp_cache_set( 'last_changed', microtime(), 'posts' );
}
...
?>

其他

英文文档:https://developer.wordpress.org/reference/functions/clean_post_cache/