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