如果缓存键尚不存在,则将数据添加到缓存。
原型
wp_cache_add( int|string $key, mixed $data, string $group = '', int $expire )
参数
$key
(int|string)
(Required)
用于以后检索的缓存键。
$data
(mixed)
(Required)
要添加到缓存的数据。
$group
(string)
(Optional)
要添加缓存的组。允许跨组使用相同的密钥。
$expire
(int)
(Optional)
当缓存数据到期时,以秒为单位。默认为0(无到期)。
返回值
(bool)
如果缓存键和组已存在则为False,成功时为true。
源文件
路径:wp-includes/cache.php
<?php
...
function wp_cache_add( $key, $data, $group = '', $expire = 0 ) {
global $wp_object_cache;
return $wp_object_cache->add( $key, $data, $group, (int) $expire );
}
...
?>
其他
英文文档:https://developer.wordpress.org/reference/functions/wp_cache_add/