wp_cache_incr()
云策文档标注
概述
wp_cache_incr() 是 WordPress 中用于递增缓存项数值的函数,通过调用 WP_Object_Cache::incr() 实现。它适用于需要更新缓存数值的场景,如计数器或统计。
关键要点
- 函数用于递增缓存项的数值,要求缓存项为数字类型。
- 参数包括:$key(必需,缓存键)、$offset(可选,递增值,默认为1)、$group(可选,缓存组,默认为空)。
- 返回值:成功时返回新值(整数),失败时返回 false。
- 自 WordPress 3.3.0 版本引入,是核心缓存 API 的一部分。
代码示例
function wp_cache_incr( $key, $offset = 1, $group = '' ) {
global $wp_object_cache;
return $wp_object_cache->incr( $key, $offset, $group );
}
原文内容
Increments numeric cache item’s value.
Description
See also
Parameters
$keyint|stringrequired-
The key for the cache contents that should be incremented.
$offsetintoptional-
The amount by which to increment the item’s value.
Default:
1 $groupstringoptional-
The group the key is in. Default empty.
Source
function wp_cache_incr( $key, $offset = 1, $group = '' ) {
global $wp_object_cache;
return $wp_object_cache->incr( $key, $offset, $group );
}
Changelog
| Version | Description |
|---|---|
| 3.3.0 | Introduced. |