Пример #1
0
 public static function cas($k, $ov, $nv)
 {
     if (function_exists('apc_cas')) {
         return apc_cas($k, $ov, $nv);
     } elseif (function_exists('apcu_cas')) {
         return apcu_cas($k, $ov, $nv);
     }
     return false;
 }
Пример #2
0
 public function testApcu()
 {
     $key = __CLASS__;
     apcu_delete($key);
     $this->assertFalse(apcu_exists($key));
     $this->assertTrue(apcu_add($key, 123));
     $this->assertTrue(apcu_exists($key));
     $this->assertSame(array($key => -1), apcu_add(array($key => 123)));
     $this->assertSame(123, apcu_fetch($key));
     $this->assertTrue(apcu_store($key, 124));
     $this->assertSame(124, apcu_fetch($key));
     $this->assertSame(125, apcu_inc($key));
     $this->assertSame(124, apcu_dec($key));
     $this->assertTrue(apcu_cas($key, 124, 123));
     $this->assertFalse(apcu_cas($key, 124, 123));
     $this->assertTrue(apcu_delete($key));
     $this->assertFalse(apcu_delete($key));
     $this->assertArrayHasKey('cache_list', apcu_cache_info());
 }
Пример #3
0
 /**
  * Internal method to set an item only if token matches
  *
  * @param  mixed  $token
  * @param  string $normalizedKey
  * @param  mixed  $value
  * @return bool
  * @see    getItem()
  * @see    setItem()
  */
 protected function internalCheckAndSetItem(&$token, &$normalizedKey, &$value)
 {
     if (is_int($token) && is_int($value)) {
         return apcu_cas($normalizedKey, $token, $value);
     }
     return parent::internalCheckAndSetItem($token, $normalizedKey, $value);
 }
Пример #4
0
 /**
  * Compare and set
  *
  * @param string $key
  * @param mixed $old
  * @param mixed $new
  * @return bool
  */
 public function cas($key, $old, $new)
 {
     // apc only does cas for ints
     if (is_int($old) and is_int($new)) {
         return apcu_cas($this->getPrefix() . $key, $old, $new);
     } else {
         return $this->casEmulated($key, $old, $new);
     }
 }
Пример #5
0
 function apc_cas($key, $old, $new)
 {
     return apcu_cas($key, $old, $new);
 }
Пример #6
0
 function apc_cas($key, $old, $new)
 {
     apcu_cas($key, $old, $new);
 }
Пример #7
0
 /**
  * Sets a new value if a key has a certain value.
  *
  * Sets a new value if a key has a certain value. This function only works
  * when $old and $new are longs.
  *
  * @param string $key Key of the value to compare and set.
  * @param int    $old The value to compare the key against.
  * @param int    $new The value to set the key to.
  *
  * @return bool TRUE on success, FALSE on failure.
  */
 public function cas($key, $old, $new)
 {
     return apcu_cas($this->persistentId . 'd ' . $key, $old, $new);
 }
Пример #8
0
 public function cas($key, $old, $new)
 {
     return apcu_cas($key, $old, $new);
 }