MatthiasMullie\Scrapbook\Buffered\Utils\Defer::decrement PHP Метод

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

public decrement ( string $key, integer $offset, integer $initial, integer $expire )
$key string
$offset integer
$initial integer
$expire integer
    public function decrement($key, $offset, $initial, $expire)
    {
        $this->doIncrement(__FUNCTION__, $key, $offset, $initial, $expire);
    }

Usage Example

Пример #1
0
 /**
  * {@inheritdoc}
  */
 public function decrement($key, $offset = 1, $initial = 0, $expire = 0)
 {
     if ($offset <= 0 || $initial < 0) {
         return false;
     }
     // get existing value (from real cache or memory) so we know what to
     // increment in memory (where we may not have anything yet, so we should
     // adjust our initial value to what's already in real cache)
     $value = $this->get($key);
     if ($value === false) {
         $value = $initial + $offset;
     }
     if (!is_numeric($value) || !is_numeric($offset)) {
         return false;
     }
     // store the value in memory, so that when we ask for it again later
     // in this same request, we get the value we just set
     $value = max(0, $value - $offset);
     $success = $this->local->set($key, $value, $expire);
     if ($success === false) {
         return false;
     }
     $this->defer->decrement($key, $offset, $initial, $expire);
     return $value;
 }