将数据保存到缓存。
原型
wp_cache_set( int|string $key, mixed $data, string $group = '', int $expire )
描述
与wp_cache_add()和wp_cache_replace()不同,它始终会写入数据。
参考:
- WP_Object_Cache::set()
参数
$key
(int|string)
(Required)
用于以后检索的缓存键。
$data
(mixed)
(Required)
要存储在缓存中的内容。
$group
(string)
(Optional)
何处对缓存内容进行分组。允许跨组使用相同的密钥。
$expire
(int)
(Optional)
何时使缓存内容到期,以秒为单位。默认为0(无到期)。
返回值
(bool)
失败时失败,成功时失败
源文件
路径:wp-includes/cache.php
<?php
...
function wp_cache_set( $key, $data, $group = '', $expire = 0 ) {
global $wp_object_cache;
return $wp_object_cache->set( $key, $data, $group, (int) $expire );
}
...
?>
其他
英文文档:https://developer.wordpress.org/reference/functions/wp_cache_set/