wp_cache_set_multiple()
云策文档标注
概述
wp_cache_set_multiple() 函数用于在一次调用中向缓存设置多个键值对,提高缓存操作效率。它封装了 WP_Object_Cache::set_multiple() 方法,支持分组和过期时间设置。
关键要点
- 函数签名:wp_cache_set_multiple( array $data, $group = '', $expire = 0 )
- 参数:$data(必需,键值对数组),$group(可选,分组标识,默认空),$expire(可选,过期时间秒数,默认0表示永不过期)
- 返回值:布尔数组,按键分组,成功返回 true,失败返回 false
- 相关函数:WP_Object_Cache::set_multiple()、wp_cache_set_multiple_salted()、wp_prime_network_option_caches()、wp_prime_option_caches()
- 引入版本:WordPress 6.0.0
代码示例
function wp_cache_set_multiple( array $data, $group = '', $expire = 0 ) {
global $wp_object_cache;
return $wp_object_cache->set_multiple( $data, $group, (int) $expire );
}
原文内容
Sets 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_set_multiple( array $data, $group = '', $expire = 0 ) {
global $wp_object_cache;
return $wp_object_cache->set_multiple( $data, $group, (int) $expire );
}
Changelog
| Version | Description |
|---|---|
| 6.0.0 | Introduced. |