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_object_cache 对象缓存的类
  • WP_Object_Cache::add()

修改记录

Since 2.0.0

源文件

wp-includes/cache.php