函数文档

clean_network_cache()

💡 云策文档标注

概述

clean_network_cache() 函数用于从对象缓存中移除一个或多个网络。它通过 wp_cache_delete_multiple() 删除缓存项,并触发 clean_network_cache 钩子。

关键要点

  • 参数 $ids 接受整数或数组,指定要移除的网络 ID。
  • 函数内部检查 $_wp_suspend_cache_invalidation 全局变量,若设置则跳过操作。
  • 使用 wp_cache_delete_multiple() 批量删除缓存,并调用 wp_cache_set_last_changed() 更新缓存组最后修改时间。
  • 触发 clean_network_cache 钩子,允许开发者执行自定义操作。

代码示例

clean_network_cache( $ids ) {
    global $_wp_suspend_cache_invalidation;

    if ( ! empty( $_wp_suspend_cache_invalidation ) ) {
        return;
    }

    $network_ids = (array) $ids;
    wp_cache_delete_multiple( $network_ids, 'networks' );

    foreach ( $network_ids as $id ) {
        do_action( 'clean_network_cache', $id );
    }

    wp_cache_set_last_changed( 'networks' );
}

注意事项

  • 函数在 WordPress 4.6.0 版本引入。
  • 相关函数包括 wp_cache_set_last_changed() 和 wp_cache_delete_multiple()。
  • 钩子 clean_network_cache 在缓存移除后立即触发,可用于扩展功能。

📄 原文内容

Removes a network from the object cache.

Parameters

$idsint|arrayrequired
Network ID or an array of network IDs to remove from cache.

Source

function clean_network_cache( $ids ) {
	global $_wp_suspend_cache_invalidation;

	if ( ! empty( $_wp_suspend_cache_invalidation ) ) {
		return;
	}

	$network_ids = (array) $ids;
	wp_cache_delete_multiple( $network_ids, 'networks' );

	foreach ( $network_ids as $id ) {
		/**
		 * Fires immediately after a network has been removed from the object cache.
		 *
		 * @since 4.6.0
		 *
		 * @param int $id Network ID.
		 */
		do_action( 'clean_network_cache', $id );
	}

	wp_cache_set_last_changed( 'networks' );
}

Hooks

do_action( ‘clean_network_cache’, int $id )

Fires immediately after a network has been removed from the object cache.

Changelog

Version Description
4.6.0 Introduced.