Exemplo n.º 1
0
 function items($cacheId)
 {
     $fullPrefix = \Cachet\Helper::formatKey([$this->prefix, $cacheId]);
     $keyRegex = "~^" . preg_quote($fullPrefix, "~") . "~";
     $iter = new \APCIterator('user', $keyRegex, APC_ITER_VALUE, $this->iteratorChunkSize);
     return new \Cachet\Util\MapIterator($iter, function ($item) {
         return $item['value'];
     });
 }
Exemplo n.º 2
0
 private function change($method, $key, $by = 1)
 {
     $memcache = $this->connector->memcache ?: $this->connector->connect();
     $formattedKey = \Cachet\Helper::formatKey([$this->prefix, $this->cacheId, $key]);
     $value = $memcache->{$method}($formattedKey, abs($by));
     if ($value === false) {
         if ($memcache->getResultCode() == self::NOT_FOUND) {
             if ($method == 'decrement') {
                 throw new \OutOfBoundsException("Memcache counters cannot be decremented past 0");
             }
             $value = $this->initialise($memcache, $method, $key, $formattedKey, $by);
         } else {
             throw $this->memcacheException($memcache);
         }
     } else {
         $this->ensureValidValue($memcache, $formattedKey, $value);
     }
     return (int) $value ?: 0;
 }
Exemplo n.º 3
0
 private function change($method, $key, $by)
 {
     $formattedKey = \Cachet\Helper::formatKey([$this->prefix, $this->cacheId, $key]);
     $value = $method($formattedKey, abs($by), $success);
     if (!$success) {
         $check = false;
         if ($this->locker) {
             $this->locker->acquire($this->cacheId, $key);
             $check = apc_fetch($formattedKey);
             if ($check !== false) {
                 $value = $method($formattedKey, abs($by), $success);
             }
         }
         if ($check === false) {
             $this->set($key, $by);
             $value = $by;
         }
         if ($this->locker) {
             $this->locker->release($this->cacheId, $key);
         }
     }
     return $value;
 }
Exemplo n.º 4
0
 function decrement($key, $by = 1)
 {
     $redis = $this->connector->redis ?: $this->connector->connect();
     $key = \Cachet\Helper::formatKey([$this->prefix, 'counter', $key]);
     return $redis->decrBy($key, $by);
 }
Exemplo n.º 5
0
 protected function flushStore($cacheId)
 {
     $prefix = \Cachet\Helper::formatKey([$this->prefix, $cacheId]);
     xcache_unset_by_prefix($prefix);
 }
Exemplo n.º 6
0
 function decrement($key, $by = 1)
 {
     $formatted = \Cachet\Helper::formatKey([$this->prefix, 'counter', $key]);
     $value = xcache_dec($formatted, $by, $this->counterTTL);
     return $value;
 }
Exemplo n.º 7
0
 protected function deleteFromStore($cacheId, $key)
 {
     $formattedKey = \Cachet\Helper::formatKey([$this->prefix, $cacheId, $key]);
     $memcache = $this->connector->memcache ?: $this->connector->connect();
     return $memcache->delete($formattedKey);
 }
Exemplo n.º 8
0
 function set($key, $value)
 {
     $formattedKey = \Cachet\Helper::formatKey(['counter', $key]);
     $this->cache->set($formattedKey, $value);
 }
Exemplo n.º 9
0
 function keys($cacheId)
 {
     $prefix = \Cachet\Helper::formatKey([$this->prefix, $cacheId]) . "/";
     $len = strlen($prefix);
     $redis = $this->connector->redis ?: $this->connector->connect();
     $redisKeys = $redis->keys("{$prefix}*");
     $keys = [];
     foreach ($redisKeys as $key) {
         $keys[] = substr($key, $len);
     }
     sort($keys);
     return $keys;
 }