/**
  * Internal method to decrement an item.
  *
  * @param  string $normalizedKey
  * @param  int    $value
  * @return int|bool The new value on success, false on failure
  * @throws Exception\ExceptionInterface
  */
 protected function internalDecrementItem(&$normalizedKey, &$value)
 {
     $options = $this->getOptions();
     $namespace = $options->getNamespace();
     $prefix = $namespace === '' ? '' : $namespace . $options->getNamespaceSeparator();
     $internalKey = $prefix . $normalizedKey;
     return wincache_ucache_dec($internalKey, (int) $value);
 }
Example #2
0
 /**
  * Decreases a value from the shared memory storage.
  * 
  * Decreases a value from the shared memory storage. Unlike a plain
  * set($key, get($key)-$step) combination, this function also implicitly
  * performs locking.
  * 
  * @param string $key  Name of key to decrease.
  * @param int    $step Value to decrease the key by.
  * 
  * @return int The new value.
  */
 public function dec($key, $step = 1)
 {
     $newValue = wincache_ucache_dec($this->persistentId . $key, (int) $step, $success);
     if (!$success) {
         throw new SHM\InvalidArgumentException('Unable to decrease the value. Are you sure the value is int?', 302);
     }
     return $newValue;
 }
Example #3
0
 /**
  * Internal method to decrement an item.
  *
  * Options:
  *  - ttl <float>
  *    - The time-to-life
  *  - namespace <string>
  *    - The namespace to use
  *  - ignore_missing_items <boolean>
  *    - Throw exception on missing item
  *
  * @param  string $normalizedKey
  * @param  int    $value
  * @param  array  $normalizedOptions
  * @return int|boolean The new value or false on failure
  * @throws Exception
  */
 protected function internalDecrementItem(&$normalizedKey, &$value, array &$normalizedOptions)
 {
     $internalKey = $normalizedOptions['namespace'] . $this->getOptions()->getNamespaceSeparator() . $normalizedKey;
     $value = (int) $value;
     $newValue = wincache_ucache_dec($internalKey, $value);
     if ($newValue === false) {
         if (wincache_ucache_exists($internalKey)) {
             throw new Exception\RuntimeException("wincache_ucache_inc('{$internalKey}', {$value}) failed");
         } elseif (!$normalizedOptions['ignore_missing_items']) {
             throw new Exception\ItemNotFoundException("Key '{$internalKey}' not found");
         }
         $newValue = -$value;
         $this->addItem($normalizedKey, $newValue, $normalizedOptions);
     }
     return $newValue;
 }
Example #4
0
 /**
  * Increment the value of an item in the cache.
  *
  * @param  string  $key
  * @param  mixed   $value
  * @return int|bool
  */
 public function decrement($key, $value = 1)
 {
     return wincache_ucache_dec($this->getPrefixWithLocale() . $key, $value);
 }
 /**
  * Decrement a raw value
  *
  * @param	string	$id	Cache ID
  * @param	int	$offset	Step/value to reduce by
  * @return	mixed	New value on success or FALSE on failure
  */
 public function decrement($id, $offset = 1)
 {
     $success = FALSE;
     $value = wincache_ucache_dec($id, $offset, $success);
     return $success === TRUE ? $value : FALSE;
 }
Example #6
0
 /**
  * Internal method to decrement an item.
  *
  * Options:
  *  - ttl <float>
  *    - The time-to-life
  *  - namespace <string>
  *    - The namespace to use
  *
  * @param  string $normalizedKey
  * @param  int    $value
  * @param  array  $normalizedOptions
  * @return int|boolean The new value on success, false on failure
  * @throws Exception\ExceptionInterface
  */
 protected function internalDecrementItem(& $normalizedKey, & $value, array & $normalizedOptions)
 {
     $internalKey = $normalizedOptions['namespace'] . $this->getOptions()->getNamespaceSeparator() . $normalizedKey;
     return wincache_ucache_dec($internalKey, (int)$value);
 }
Example #7
0
 /**
  * Decrement an item.
  *
  * Options:
  *  - namespace <string> optional
  *    - The namespace to use (Default: namespace of object)
  *  - ignore_missing_items <boolean> optional
  *    - Throw exception on missing item or return false
  *
  * @param  string $key
  * @param  int $value
  * @param  array $options
  * @return int|boolean The new value or false or failure
  * @throws Exception
  *
  * @triggers decrementItem.pre(PreEvent)
  * @triggers decrementItem.post(PostEvent)
  * @triggers decrementItem.exception(ExceptionEvent)
  */
 public function decrementItem($key, $value, array $options = array())
 {
     $baseOptions = $this->getOptions();
     if (!$baseOptions->getWritable()) {
         return false;
     }
     $this->normalizeOptions($options);
     $this->normalizeKey($key);
     $args = new ArrayObject(array('key' => &$key, 'options' => &$options));
     try {
         $eventRs = $this->triggerPre(__FUNCTION__, $args);
         if ($eventRs->stopped()) {
             return $eventRs->last();
         }
         $internalKey = $options['namespace'] . $baseOptions->getNamespaceSeparator() . $key;
         $value = (int) $value;
         $newValue = wincache_ucache_dec($internalKey, $value);
         if ($newValue === false) {
             if (wincache_ucache_exists($internalKey)) {
                 throw new Exception\RuntimeException("wincache_ucache_dec('{$internalKey}', {$value}) failed");
             } elseif (!$options['ignore_missing_items']) {
                 throw new Exception\ItemNotFoundException("Key '{$internalKey}' not found");
             }
             $this->addItem($key, -$value, $options);
             $newValue = -$value;
         }
         return $this->triggerPost(__FUNCTION__, $args, $newValue);
     } catch (\Exception $e) {
         return $this->triggerException(__FUNCTION__, $args, $e);
     }
 }
Example #8
0
 /**
  * Decrements the value of an integer cached key
  *
  * @param string $key Identifier for the data
  * @param int $offset How much to subtract
  * @return bool|int New decremented value, false otherwise
  */
 public function decrement($key, $offset = 1)
 {
     $key = $this->_key($key);
     return wincache_ucache_dec($key, $offset);
 }
Example #9
0
 /**
  * 自减缓存(针对数值缓存)
  * @access public
  * @param string    $name 缓存变量名
  * @param int       $step 步长
  * @return false|int
  */
 public function dec($name, $step = 1)
 {
     $key = $this->getCacheKey($name);
     return wincache_ucache_dec($key, $step);
 }
Example #10
0
 public function decrement($key, $decrement)
 {
     $success = false;
     $value = wincache_ucache_dec($key, $decrement, $success);
     return $success === true ? $value : false;
 }
 public function decrement($key, $decrement = 1)
 {
     $success = false;
     if (function_exists('wincache_ucache_dec')) {
         $value = wincache_ucache_dec($key, $decrement, $success);
     } else {
         return getMessage('Cache', 'unsupported', 'Wincache');
     }
     return $success === true ? $value : false;
 }
Example #12
0
 /**
  * 递减
  *
  * 与原始decrement方法区别的是若不存指定KEY时返回false,这个会自动递减
  *
  * @param string $key
  * @param int $offset
  * @param int $lifetime 当递减失则时当作set使用
  * @return boolean
  */
 public function decrement($key, $offset = 1, $lifetime = 60)
 {
     if (wincache_ucache_dec($this->prefix . $key, $offset)) {
         return true;
     } elseif (false == wincache_ucache_exists($this->prefix . $key) && $this->set($key, $offset, $lifetime)) {
         return true;
     } else {
         return false;
     }
 }
Example #13
0
 /**
  * Decrease the value of a key by $amount.
  * 
  * If the key does not exist, this method assumes that the current value is zero.
  * This method returns the new value.
  * 
  * @param string $key
  * @param int $amount
  * @return int
  */
 public function decr($key, $amount)
 {
     $result = wincache_ucache_dec($key, $amount);
     if ($result === false) {
         wincache_ucache_set($key, 0 - $amount);
         $result = 0 - $amount;
     }
     return $result;
 }
 function decr($id, $n, $group)
 {
     $key = $this->key($id, $group);
     return wincache_ucache_dec($id, $n);
 }
 public function dec($key, $step = 1)
 {
     return wincache_ucache_dec($key, $step);
 }
 /**
  * Decrements the value of an integer cached key
  *
  * @param string $key Identifier for the data
  * @param int $offset How much to subtract
  * @return New decremented value, false otherwise
  */
 public function decrement($key, $offset = 1)
 {
     return wincache_ucache_dec($key, $offset);
 }
     } else {
         return $x;
     }
 }
 private static function wincache_stats()
Example #18
0
 /**
  * Decrements the value associated with the key.
  *
  * The third parameter has been replaced by $this->getLastDecResult();
  *
  * @see wincache_ucache_dec();
  */
 public function dec($key, $dec_by = 1)
 {
     $result = wincache_ucache_dec($key, $dec_by, $this->lastDecResult);
     $this->clearInfoArrays();
     return $result;
 }
Example #19
0
 /**
  * @inheritdoc
  */
 public function decrement($name, $offset = 1)
 {
     $success = false;
     $value = wincache_ucache_dec($name, $offset, $success);
     return $success === true ? $value : false;
 }
Example #20
0
 /**
  * Increment the value of an item in the cache.
  *
  * @param  string  $key
  * @param  mixed   $value
  * @return void
  */
 public function decrement($key, $value = 1)
 {
     return wincache_ucache_dec($this->prefix . $key, $value);
 }
Example #21
0
 /**
  * {@inheritdoc}
  */
 public function decrement($key, $step = 1)
 {
     return wincache_ucache_dec($this->key($key), $step);
 }