WP_Object_Cache::incr
Increments numeric cache item's value.
Method of the class: WP_Object_Cache{}
No Hooks.
Returns
Int|false. The item's new value on success, false on failure.
Usage
$WP_Object_Cache = new WP_Object_Cache(); $WP_Object_Cache->incr( $key, $offset, $group );
- $key(int|string) (required)
- The cache key to increment.
- $offset(int)
- The amount by which to increment the item's value.
Default:1 - $group(string)
- The group the key is in.
Default:'default'
Changelog
| Since 3.3.0 | Introduced. |
WP_Object_Cache::incr() WP Object Cache::incr code WP 6.9.1
public function incr( $key, $offset = 1, $group = 'default' ) {
if ( ! $this->is_valid_key( $key ) ) {
return false;
}
if ( empty( $group ) ) {
$group = 'default';
}
if ( $this->multisite && ! isset( $this->global_groups[ $group ] ) ) {
$key = $this->blog_prefix . $key;
}
if ( ! $this->_exists( $key, $group ) ) {
return false;
}
if ( ! is_numeric( $this->cache[ $group ][ $key ] ) ) {
$this->cache[ $group ][ $key ] = 0;
}
$offset = (int) $offset;
$this->cache[ $group ][ $key ] += $offset;
if ( $this->cache[ $group ][ $key ] < 0 ) {
$this->cache[ $group ][ $key ] = 0;
}
return $this->cache[ $group ][ $key ];
}