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']; }); }
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; }
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; }
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); }
protected function flushStore($cacheId) { $prefix = \Cachet\Helper::formatKey([$this->prefix, $cacheId]); xcache_unset_by_prefix($prefix); }
function decrement($key, $by = 1) { $formatted = \Cachet\Helper::formatKey([$this->prefix, 'counter', $key]); $value = xcache_dec($formatted, $by, $this->counterTTL); return $value; }
protected function deleteFromStore($cacheId, $key) { $formattedKey = \Cachet\Helper::formatKey([$this->prefix, $cacheId, $key]); $memcache = $this->connector->memcache ?: $this->connector->connect(); return $memcache->delete($formattedKey); }
function set($key, $value) { $formattedKey = \Cachet\Helper::formatKey(['counter', $key]); $this->cache->set($formattedKey, $value); }
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; }