QU<QU&QU;QU<QU QU.QUPsQU QU4 QU+]QUp0KQU   =QUP AQU <QU &QU(#;QUp #G{QU P#tQU0#<QU0#&QUPP%)QUP@`%-QU`p%)QUp%tQU%>QU&>78 88P88h8bN7bN7vN7uN7PuN7@bN7bN78aN7aN7`N7qN7J7M7M7M7H38}w788QUtN78tN7tN7tN7uN7p88d9x88ps8xuN7xM7xM788QUP~?QU q7QUPPBQU<QU`&QU;7QUPPBQU<QUp&QU`;7QUPPBQU<QU&QU q7QUPPBQU0<QU0& QUPPZ]QUP`Z]QU`pZQUp@ QUPQU &KQUp 0=QUPAQU`uCQUQU&KQU8=1QUpQQUPA1QU`QQU`AQU`+ QUQU@* QUQUpAQU`+-QU`Gb%QUQU@* QU0QUAQU+-QUGb%QU QU@* QU QU ACQU0QU0&KQUp@=QUPAQU`uCQUPQUP>QU>jN7jN7@N7@N7 G7 G7N7N7p8Т(9N7RSU8@kN78@N7N7xO7`QU`QU`QU88"': '.$e->getMessage() : '.'); CacheItem::log($this->logger, $message, ['exception' => $e instanceof \Exception ? $e : null, 'cache-adapter' => get_debug_type($this)]); } else { $this->namespaceVersion = $namespaceVersion; $this->ids = []; } } else { $namespaceToClear = $this->namespace.$prefix; } try { return $this->doClear($namespaceToClear) || $cleared; } catch (\Exception $e) { CacheItem::log($this->logger, 'Failed to clear the cache: '.$e->getMessage(), ['exception' => $e, 'cache-adapter' => get_debug_type($this)]); return false; } } /** * {@inheritdoc} * * @return bool */ public function deleteItem($key) { return $this->deleteItems([$key]); } /** * {@inheritdoc} * * @return bool */ public function deleteItems(array $keys) { $ids = []; foreach ($keys as $key) { $ids[$key] = $this->getId($key); unset($this->deferred[$key]); } try { if ($this->doDelete($ids)) { return true; } } catch (\Exception $e) { } $ok = true; // When bulk-delete failed, retry each item individually foreach ($ids as $key => $id) { try { $e = null; if ($this->doDelete([$id])) { continue; } } catch (\Exception $e) { } $message = 'Failed to delete key "{key}"'.($e instanceof \Exception ? ': '.$e->getMessage() : '.'); CacheItem::log($this->logger, $message, ['key' => $key, 'exception' => $e, 'cache-adapter' => get_debug_type($this)]); $ok = false; } return $ok; } /** * {@inheritdoc} */ public function getItem($key) { $id = $this->getId($key); if (isset($this->deferred[$key])) { $this->commit(); } $isHit = false; $value = null; try { foreach ($this->doFetch([$id]) as $value) { $isHit = true; } return (self::$createCacheItem)($key, $value, $isHit); } catch (\Exception $e) { CacheItem::log($this->logger, 'Failed to fetch key "{key}": '.$e->getMessage(), ['key' => $key, 'exception' => $e, 'cache-adapter' => get_debug_type($this)]); } return (self::$createCacheItem)($key, null, false); } /** * {@inheritdoc} */ public function getItems(array $keys = []) { $ids = []; $commit = false; foreach ($keys as $key) { $ids[] = $this->getId($key); $commit = $commit || isset($this->deferred[$key]); } if ($commit) { $this->commit(); } try { $items = $this->doFetch($ids); } catch (\Exception $e) { CacheItem::log($this->logger, 'Failed to fetch items: '.$e->getMessage(), ['keys' => $keys, 'exception' => $e, 'cache-adapter' => get_debug_type($this)]); $items = []; } $ids = array_combine($ids, $keys); return $this->generateItems($items, $ids); } /** * {@inheritdoc} * * @return bool */ public function save(CacheItemInterface $item) { if (!$item instanceof CacheItem) { return false; } $this->deferred[$item->getKey()] = $item; return $this->commit(); } /** * {@inheritdoc} * * @return bool */ public function saveDeferred(CacheItemInterface $item) { if (!$item instanceof CacheItem) { return false; } $this->deferred[$item->getKey()] = $item; return true; } /** * Enables/disables versioning of items. * * When versioning is enabled, clearing the cache is atomic and doesn't require listing existing keys to proceed, * but old keys may need garbage collection and extra round-trips to the back-end are required. * * Calling this method also clears the memoized namespace version and thus forces a resynchronization of it. * * @return bool the previous state of versioning */ public function enableVersioning(bool $enable = true) { $wasEnabled = $this->versioningIsEnabled; $this->versioningIsEnabled = $enable; $this->namespaceVersion = ''; $this->ids = []; return $wasEnabled; } /** * {@inheritdoc} */ public function reset() { if ($this->deferred) { $this->commit(); } $this->namespaceVersion = ''; $this->ids = []; } /** * @return array */ public function __sleep() { throw new \BadMethodCallException('Cannot serialize '.__CLASS__); } public function __wakeup() { throw new \BadMethodCallException('Cannot unserialize '.__CLASS__); } public function __destruct() { if ($this->deferred) { $this->commit(); } } private function generateItems(iterable $items, array &$keys): \Generator { $f = self::$createCacheItem; try { foreach ($items as $id => $value) { if (!isset($keys[$id])) { throw new InvalidArgumentException(sprintf('Could not match value id "%s" to keys "%s".', $id, implode('", "', $keys))); } $key = $keys[$id]; unset($keys[$id]); yield $key => $f($key, $value, true); } } catch (\Exception $e) { CacheItem::log($this->logger, 'Failed to fetch items: '.$e->getMessage(), ['keys' => array_values($keys), 'exception' => $e, 'cache-adapter' => get_debug_type($this)]); } foreach ($keys as $key) { yield $key => $f($key, null, false); } } /** * @internal */ protected function getId($key) { if ($this->versioningIsEnabled && '' === $this->namespaceVersion) { $this->ids = []; $this->namespaceVersion = '1'.static::NS_SEPARATOR; try { foreach ($this->doFetch([static::NS_SEPARATOR.$this->namespace]) as $v) { $this->namespaceVersion = $v; } $e = true; if ('1'.static::NS_SEPARATOR === $this->namespaceVersion) { $this->namespaceVersion = self::formatNamespaceVersion(time()); $e = $this->doSave([static::NS_SEPARATOR.$this->namespace => $this->namespaceVersion], 0); } } catch (\Exception $e) { } if (true !== $e && [] !== $e) { $message = 'Failed to save the new namespace'.($e instanceof \Exception ? ': '.$e->getMessage() : '.'); CacheItem::log($this->logger, $message, ['exception' => $e instanceof \Exception ? $e : null, 'cache-adapter' => get_debug_type($this)]); } } if (\is_string($key) && isset($this->ids[$key])) { return $this->namespace.$this->namespaceVersion.$this->ids[$key]; } \assert('' !== CacheItem::validateKey($key)); $this->ids[$key] = $key; if (\count($this->ids) > 1000) { $this->ids = \array_slice($this->ids, 500, null, true); // stop memory leak if there are many keys } if (null === $this->maxIdLength) { return $this->namespace.$this->namespaceVersion.$key; } if (\strlen($id = $this->namespace.$this->namespaceVersion.$key) > $this->maxIdLength) { // Use MD5 to favor speed over security, which is not an issue here $this->ids[$key] = $id = substr_replace(base64_encode(hash('md5', $key, true)), static::NS_SEPARATOR, -(\strlen($this->namespaceVersion) + 2)); $id = $this->namespace.$this->namespaceVersion.$id; } return $id; } /** * @internal */ public static function handleUnserializeCallback(string $class) { throw new \DomainException('Class not found: '.$class); } private static function formatNamespaceVersion(int $value): string { return strtr(substr_replace(base64_encode(pack('V', $value)), static::NS_SEPARATOR, 5), '/', '_'); } }