lithium\storage\Cache::decrement PHP Метод

decrement() публичный статический Метод

Performs a decrement operation on specified numeric cache item from the given cache configuration.
public static decrement ( string $name, string $key, integer $offset = 1, array $options = [] ) : integer | boolean
$name string Name of the cache configuration to use.
$key string Key of numeric cache item to decrement
$offset integer Offset to decrement - defaults to 1.
$options array Options for this method. - `'conditions'`: A function or item that must return or evaluate to `true` in order to continue operation.
Результат integer | boolean Item's new value on successful decrement, false otherwise.
    public static function decrement($name, $key, $offset = 1, array $options = array())
    {
        $options += array('conditions' => null);
        if (is_callable($options['conditions']) && !$options['conditions']()) {
            return false;
        }
        try {
            $adapter = static::adapter($name);
        } catch (ConfigException $e) {
            return false;
        }
        $key = static::key($key);
        $params = compact('key', 'offset');
        return static::_filter(__FUNCTION__, $params, function ($self, $params) use($adapter) {
            return $adapter->decrement($params['key'], $params['offset']);
        });
    }

Usage Example

Пример #1
0
 public function testDecrement()
 {
     $config = array('default' => array('adapter' => 'Memory', 'filters' => array()));
     Cache::config($config);
     $result = Cache::config();
     $expected = $config;
     $this->assertEqual($expected, $result);
     $result = Cache::write('default', 'decrement', 5, '+1 minute');
     $this->assertTrue($result);
     $result = Cache::decrement('default', 'decrement');
     $this->assertTrue($result);
     $result = Cache::read('default', 'decrement');
     $this->assertEqual(4, $result);
 }