wp_cache_set_multiple_salted()
云策文档标注
概述
wp_cache_set_multiple_salted() 函数用于将多个带时间戳(salt)的数据存储到缓存中,通过整合 salt 值并调用 wp_cache_set_multiple() 实现批量操作。
关键要点
- 参数:$data(必需,要存储的数据数组)、$group(必需,缓存组)、$salt(必需,时间戳或时间戳数组)、$expire(可选,过期时间,默认 0 表示永不过期)。
- 返回值:返回布尔值数组,每个键对应 true(成功)或 false(失败)。
- 内部实现:将 salt 转换为字符串,为每个数据项添加 salt 信息,然后调用 wp_cache_set_multiple()。
- 相关函数:wp_cache_set_multiple() 用于批量设置缓存值。
- 引入版本:WordPress 6.9.0。
代码示例
function wp_cache_set_multiple_salted( $data, $group, $salt, $expire = 0 ) {
$salt = is_array( $salt ) ? implode( ':', $salt ) : $salt;
$new_cache = array();
foreach ( $data as $key => $value ) {
$new_cache[ $key ] = array(
'data' => $value,
'salt' => $salt,
);
}
return wp_cache_set_multiple( $new_cache, $group, $expire );
}
原文内容
Stores multiple pieces of salted data in the cache.
Parameters
$datamixedrequired-
Data to be stored in the cache for all keys.
$groupstringrequired-
Group to which the cached data belongs.
$saltstring|string[]required-
The timestamp (or multiple timestamps if an array) indicating when the cache group(s) were last updated.
$expireintoptional-
When to expire the cache contents, in seconds.
Default 0 (no expiration).
Source
function wp_cache_set_multiple_salted( $data, $group, $salt, $expire = 0 ) {
$salt = is_array( $salt ) ? implode( ':', $salt ) : $salt;
$new_cache = array();
foreach ( $data as $key => $value ) {
$new_cache[ $key ] = array(
'data' => $value,
'salt' => $salt,
);
}
return wp_cache_set_multiple( $new_cache, $group, $expire );
}
Changelog
| Version | Description |
|---|---|
| 6.9.0 | Introduced. |