WordPress 常用函数 / wp_cache_add
简介
如果 cache key 不存在,就添加数据到缓存中。
用法
<?php wp_cache_add($key, $data, $group = '', $expire = 0); ?>
参数
$key
(int|string) (required) cache key,用来以后获取缓存的数据
Default: 无
$data
(mixed) (required) 要缓存的数据。
Default: 无
$group
(string) (optional) 缓存添加到的组。
Default: ‘default’
$expire
(int) (optional) 要缓存的时间。
Default: 0,如果内存缓存,0为永久的意思。
返回值
(bool)
如果 cache key 已经存在,返回 false,否则返回 true。
相关:
- 使用 wp_cache_set() 把数据写到缓存中。
- 使用 wp_cache_get() 到缓存中读取数据。
- 使用 wp_cache_delete() 删除缓存。
