wp_cache_set()
wp_cache_set( int|string $key, mixed $data, string $group = ”, int $expire )
将数据保存到缓存。
Saves the data to the cache.
说明(Description)
与wp_cache_add()和wp_cache_replace()不同的是,它将始终写入数据。另请参阅WP_Object_Cache::set()
参数(Parameters)
参数 | 类型 | 说明 |
---|---|---|
$key | (int | string) | 稍后用于检索的缓存键。 |
$data | (mixed) | 要存储在缓存中的内容。 |
$group | (string) | 缓存内容的分组位置。使同一个密钥可以跨组使用。 |
$expire | (int) | 缓存内容的过期时间(秒)。默认值为0(无过期)。 |
源码(Source)
/** * Saves the data to the cache. * * @since 2.0.0 * * @global WP_Object_Cache $wp_object_cache * * @param int|string $key What to call the contents in the cache * @param mixed $data The contents to store in the cache * @param string $group Where to group the cache contents * @param int $expire When to expire the cache contents * @return bool False on failure, true on success */ function wp_cache_set( $key, $data, $group = '', $expire = 0 ) { global $wp_object_cache; return $wp_object_cache->set( $key, $data, $group, (int) $expire ); }
更新版本 | 源码位置 | 使用 | 被使用 |
---|---|---|---|
2.0.0 | wp-includes/cache.php | 18 | 20 |
wp_cache_set() 为WP2原创文章,链接:https://www.wp2.cn/functions/wp_cache_set/