函数文档

wp_cache_flush_group()

💡 云策文档标注

概述

wp_cache_flush_group() 函数用于移除指定缓存组中的所有缓存项,前提是对象缓存实现支持此功能。开发者需先检查支持性,再调用此函数。

关键要点

  • 函数移除缓存组中的所有项,但需对象缓存实现支持 group flushing 功能。
  • 调用前必须使用 wp_cache_supports( 'flush_group' ) 检查支持性。
  • 参数 $group 为字符串类型,必需,指定要移除的缓存组名称。
  • 返回布尔值:成功移除返回 true,否则返回 false。
  • 函数内部调用 WP_Object_Cache::flush_group() 方法实现功能。
  • 此函数在 WordPress 6.1.0 版本中引入。

代码示例

function wp_cache_flush_group( $group ) {
    global $wp_object_cache;

    return $wp_object_cache->flush_group( $group );
}

注意事项

  • 确保对象缓存实现支持 flush_group 功能,否则函数可能无效。
  • 相关函数包括 wp_cache_supports() 用于检查支持性,WP_Object_Cache::flush_group() 为底层实现。

📄 原文内容

Removes all cache items in a group, if the object cache implementation supports it.

Description

Before calling this function, always check for group flushing support using the wp_cache_supports( 'flush_group' ) function.

See also

Parameters

$groupstringrequired
Name of group to remove from cache.

Return

bool True if group was flushed, false otherwise.

Source

function wp_cache_flush_group( $group ) {
	global $wp_object_cache;

	return $wp_object_cache->flush_group( $group );
}

Changelog

Version Description
6.1.0 Introduced.