wp_cache_get_multiple()
云策文档标注
概述
wp_cache_get_multiple() 函数用于在一次调用中从缓存中检索多个值,提高效率。它调用 WP_Object_Cache::get_multiple() 方法实现功能。
关键要点
- 参数:$keys(必需,数组类型,缓存键名数组)、$group(可选,字符串类型,缓存分组,默认为空)、$force(可选,布尔类型,是否强制从持久缓存更新本地缓存,默认为 false)。
- 返回值:数组类型,按键名分组,每个值在成功时为缓存内容,失败时为 false。
- 相关函数:与 WP_Object_Cache::get_multiple() 关联,并用于多个核心函数如 wp_prime_option_caches() 和 WP_Query::get_posts()。
- 版本历史:自 WordPress 5.5.0 版本引入。
代码示例
function wp_cache_get_multiple( $keys, $group = '', $force = false ) {
global $wp_object_cache;
return $wp_object_cache->get_multiple( $keys, $group, $force );
}
原文内容
Retrieves multiple values from the cache in one call.
Description
See also
Parameters
$keysarrayrequired-
Array of keys under which the cache contents are stored.
$groupstringoptional-
Where the cache contents are grouped. Default empty.
$forcebooloptional-
Whether to force an update of the local cache from the persistent cache.
Default:
false
Source
function wp_cache_get_multiple( $keys, $group = '', $force = false ) {
global $wp_object_cache;
return $wp_object_cache->get_multiple( $keys, $group, $force );
}
Changelog
| Version | Description |
|---|---|
| 5.5.0 | Introduced. |