wp_cache_add_multiple()
云策文档标注
概述
wp_cache_add_multiple() 函数用于一次性向缓存中添加多个键值对,提高缓存操作效率。它调用 WP_Object_Cache::add_multiple() 方法实现功能。
关键要点
- 参数 $data 为必需数组,包含要设置的键值对。
- 可选参数 $group 用于分组缓存内容,默认空字符串。
- 可选参数 $expire 设置缓存过期时间(秒),默认 0 表示永不过期。
- 返回值为布尔数组,按键分组,成功返回 true,若缓存键和组已存在则返回 false。
- 该函数在 WordPress 6.0.0 版本中引入。
代码示例
function wp_cache_add_multiple( array $data, $group = '', $expire = 0 ) {
global $wp_object_cache;
return $wp_object_cache->add_multiple( $data, $group, (int) $expire );
}
原文内容
Adds multiple values to the cache in one call.
Description
See also
Parameters
$dataarrayrequired-
Array of keys and values to be set.
$groupstringoptional-
Where the cache contents are grouped. Default empty.
$expireintoptional-
When to expire the cache contents, in seconds.
Default 0 (no expiration).
Source
function wp_cache_add_multiple( array $data, $group = '', $expire = 0 ) {
global $wp_object_cache;
return $wp_object_cache->add_multiple( $data, $group, (int) $expire );
}
Changelog
| Version | Description |
|---|---|
| 6.0.0 | Introduced. |