Example #1
0
 /**
  * @inheritdoc
  */
 public function increment($name, $offset = 1)
 {
     $success = false;
     $value = wincache_ucache_inc($name, $offset, $success);
     return $success === true ? $value : false;
 }
Example #2
0
 public function modifyInteger($key, $offset, &$success = null)
 {
     return @wincache_ucache_inc($key, $offset, $success);
 }
 /**
  * Increment a raw value
  *
  * @param	string	$id	Cache ID
  * @param	int	$offset	Step/value to add
  * @return	mixed	New value on success or FALSE on failure
  */
 public function increment($id, $offset = 1)
 {
     $success = FALSE;
     $value = wincache_ucache_inc($id, $offset, $success);
     return $success === TRUE ? $value : FALSE;
 }
Example #4
0
 /**
  * Internal method to increment 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 internalIncrementItem(& $normalizedKey, & $value, array & $normalizedOptions)
 {
     $internalKey = $normalizedOptions['namespace'] . $this->getOptions()->getNamespaceSeparator() . $normalizedKey;
     return wincache_ucache_inc($internalKey, (int)$value);
 }
 function incr2($id, $n, $group)
 {
     $key = $this->key($id, $group);
     return wincache_ucache_inc($key, $n);
 }
 /**
  * Increments the value associated with the key
  *
  * The third parameter has been replaced by $this->getLastIncResult();
  *
  * @see wincache_ucache_inc();
  */
 public function inc($key, $inc_by = 1)
 {
     $result = wincache_ucache_inc($key, $inc_by, $this->last_inc_result);
     $this->clearInfoArrays();
     return $result;
 }
Example #7
0
 /**
  * Increment 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 on failure
  * @throws Exception
  *
  * @triggers incrementItem.pre(PreEvent)
  * @triggers incrementItem.post(PostEvent)
  * @triggers incrementItem.exception(ExceptionEvent)
  */
 public function incrementItem($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_inc($internalKey, $value);
         if ($newValue === false) {
             if (wincache_ucache_exists($internalKey)) {
                 throw new Exception\RuntimeException("wincache_ucache_inc('{$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);
     }
 }
 /**
  * Internal method to increment an item.
  *
  * @param  string $normalizedKey
  * @param  int    $value
  * @return int|bool The new value on success, false on failure
  * @throws Exception\ExceptionInterface
  */
 protected function internalIncrementItem(&$normalizedKey, &$value)
 {
     $options = $this->getOptions();
     $namespace = $options->getNamespace();
     $prefix = $namespace === '' ? '' : $namespace . $options->getNamespaceSeparator();
     $internalKey = $prefix . $normalizedKey;
     return wincache_ucache_inc($internalKey, (int) $value);
 }
Example #9
0
 /**
  * 自增缓存(针对数值缓存)
  * @access public
  * @param string    $name 缓存变量名
  * @param int       $step 步长
  * @return false|int
  */
 public function inc($name, $step = 1)
 {
     $key = $this->getCacheKey($name);
     return wincache_ucache_inc($key, $step);
 }
Example #10
0
 public function increment($key, $increment)
 {
     $success = false;
     $value = wincache_ucache_inc($key, $increment, $success);
     return $success === true ? $value : false;
 }
 public function increment($key, $increment = 1)
 {
     $success = false;
     if (function_exists('wincache_ucache_inc')) {
         $value = wincache_ucache_inc($key, $increment, $success);
     } else {
         return getMessage('Cache', 'unsupported', 'Wincache');
     }
     return $success === true ? $value : false;
 }
Example #12
0
 /**
  * 递增
  *
  * 与原始increment方法区别的是若不存指定KEY时返回false,这个会自动递增
  *
  * @param string $key
  * @param int $offset
  * @param int $lifetime 当递减失则时当作set使用
  * @return boolean
  */
 public function increment($key, $offset = 1, $lifetime = 60)
 {
     if (wincache_ucache_inc($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
 /**
  * Increase 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 incr($key, $amount)
 {
     $result = wincache_ucache_inc($key, $amount);
     if ($result === false) {
         wincache_ucache_set($key, $amount);
         $result = $amount;
     }
     return $result;
 }
Example #14
0
 /**
  * Internal method to increment 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 internalIncrementItem(&$normalizedKey, &$value, array &$normalizedOptions)
 {
     $internalKey = $normalizedOptions['namespace'] . $this->getOptions()->getNamespaceSeparator() . $normalizedKey;
     $value = (int) $value;
     $newValue = wincache_ucache_inc($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;
 }
 public function inc($key, $step = 1)
 {
     return wincache_ucache_inc($key, $step);
 }
Example #16
0
 /**
  * Increment the value of an item in the cache.
  *
  * @param  string  $key
  * @param  mixed   $value
  * @return int|bool
  */
 public function increment($key, $value = 1)
 {
     return wincache_ucache_inc($this->getPrefixWithLocale() . $key, $value);
 }
Example #17
0
 /**
  * Use key as a counter and add integet value to it
  */
 public function counter_add($key, $value)
 {
     if ($value == 0) {
         return true;
     }
     $storage_key = $this->get_item_key($key);
     $r = wincache_ucache_inc($storage_key, $value);
     if (!$r) {
         // it doesnt initialize counter by itself
         $this->counter_set($key, 0);
     }
     return $r;
 }
Example #18
0
 /**
  * Increases a value from the shared memory storage.
  * 
  * Increases 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 increase.
  * @param int    $step Value to increase the key by.
  * 
  * @return int The new value.
  */
 public function inc($key, $step = 1)
 {
     $newValue = wincache_ucache_inc($this->persistentId . $key, (int) $step, $success);
     if (!$success) {
         throw new SHM\InvalidArgumentException('Unable to increase the value. Are you sure the value is int?', 301);
     }
     return $newValue;
 }
 {
     $name = self::getMemoryName($name);
     $x = wincache_ucache_get($name, $suc);
     if ($suc == false) {
         return null;
Example #20
0
 /**
  * Increments the group value to simulate deletion of all keys under a group
  * old values will remain in storage until they expire.
  *
  * @param string $group The group to clear.
  * @return bool success
  */
 public function clearGroup($group)
 {
     $success = null;
     wincache_ucache_inc($this->_config['prefix'] . $group, 1, $success);
     return $success;
 }
 /**
  * Increments the value of an integer cached key
  *
  * @param string $key Identifier for the data
  * @param integer $offset How much to increment
  * @return New incremented value, false otherwise
  */
 public function increment($key, $offset = 1)
 {
     return wincache_ucache_inc($key, $offset);
 }
Example #22
0
 /**
  * Tests that configuring groups for stored keys return the correct values when read/written
  * Shows that altering the group value is equivalent to deleting all keys under the same
  * group
  *
  * @return void
  */
 public function testGroupsReadWrite()
 {
     Cache::config('wincache_groups', array('engine' => 'Wincache', 'duration' => 0, 'groups' => array('group_a', 'group_b'), 'prefix' => 'test_'));
     $this->assertTrue(Cache::write('test_groups', 'value', 'wincache_groups'));
     $this->assertEquals('value', Cache::read('test_groups', 'wincache_groups'));
     wincache_ucache_inc('test_group_a');
     $this->assertFalse(Cache::read('test_groups', 'wincache_groups'));
     $this->assertTrue(Cache::write('test_groups', 'value2', 'wincache_groups'));
     $this->assertEquals('value2', Cache::read('test_groups', 'wincache_groups'));
     wincache_ucache_inc('test_group_b');
     $this->assertFalse(Cache::read('test_groups', 'wincache_groups'));
     $this->assertTrue(Cache::write('test_groups', 'value3', 'wincache_groups'));
     $this->assertEquals('value3', Cache::read('test_groups', 'wincache_groups'));
 }
 /**
  * Increments the group value to simulate deletion of all keys under a group
  * old values will remain in storage until they expire.
  *
  * @return boolean success
  **/
 public function clearGroup($group)
 {
     wincache_ucache_inc($this->settings['prefix'] . $group, 1, $success);
     return $success;
 }
Example #24
0
 /**
  * Increment the value of an item in the cache.
  *
  * @param  string  $key
  * @param  mixed   $value
  * @return void
  */
 public function increment($key, $value = 1)
 {
     return wincache_ucache_inc($this->prefix . $key, $value);
 }
Example #25
0
 /**
  * {@inheritdoc}
  */
 public function increment($key, $step = 1)
 {
     return wincache_ucache_inc($this->key($key), $step);
 }