函数文档

wp_cache_delete()

💡 云策文档标注

概述

wp_cache_delete() 函数用于删除 WordPress 对象缓存中指定键和组的缓存内容。它通过调用 WP_Object_Cache::delete() 方法实现,返回布尔值表示操作成功与否。

关键要点

  • 函数签名:wp_cache_delete( $key, $group = '' ),其中 $key 为必需参数(整数或字符串),$group 为可选参数(字符串,默认为空)。
  • 返回值为布尔类型:成功删除返回 true,失败返回 false。
  • 内部实现依赖于全局 $wp_object_cache 对象,直接调用其 delete() 方法。
  • 该函数在 WordPress 核心和插件中广泛使用,例如清理主题、插件、用户、文章等缓存。

代码示例

function wp_cache_delete( $key, $group = '' ) {
    global $wp_object_cache;
    return $wp_object_cache->delete( $key, $group );
}

📄 原文内容

Removes the cache contents matching key and group.

Description

See also

Parameters

$keyint|stringrequired
What the contents in the cache are called.
$groupstringoptional
Where the cache contents are grouped. Default empty.

Return

bool True on successful removal, false on failure.

Source

function wp_cache_delete( $key, $group = '' ) {
	global $wp_object_cache;

	return $wp_object_cache->delete( $key, $group );
}

Changelog

Version Description
2.0.0 Introduced.