From bf6655a534a6775d30cafa67bd801276bda1d98d Mon Sep 17 00:00:00 2001 From: polo Date: Tue, 13 Aug 2024 23:45:21 +0200 Subject: =?UTF-8?q?VERSION=200.2=20doctrine=20ORM=20et=20entit=C3=A9s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../orm/src/Cache/Region/DefaultRegion.php | 113 +++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 vendor/doctrine/orm/src/Cache/Region/DefaultRegion.php (limited to 'vendor/doctrine/orm/src/Cache/Region/DefaultRegion.php') diff --git a/vendor/doctrine/orm/src/Cache/Region/DefaultRegion.php b/vendor/doctrine/orm/src/Cache/Region/DefaultRegion.php new file mode 100644 index 0000000..0576195 --- /dev/null +++ b/vendor/doctrine/orm/src/Cache/Region/DefaultRegion.php @@ -0,0 +1,113 @@ +name; + } + + public function contains(CacheKey $key): bool + { + return $this->cacheItemPool->hasItem($this->getCacheEntryKey($key)); + } + + public function get(CacheKey $key): CacheEntry|null + { + $item = $this->cacheItemPool->getItem($this->getCacheEntryKey($key)); + $entry = $item->isHit() ? $item->get() : null; + + if (! $entry instanceof CacheEntry) { + return null; + } + + return $entry; + } + + public function getMultiple(CollectionCacheEntry $collection): array|null + { + $keys = array_map( + $this->getCacheEntryKey(...), + $collection->identifiers, + ); + /** @var iterable $items */ + $items = $this->cacheItemPool->getItems($keys); + if ($items instanceof Traversable) { + $items = iterator_to_array($items); + } + + $result = []; + foreach ($keys as $arrayKey => $cacheKey) { + if (! isset($items[$cacheKey]) || ! $items[$cacheKey]->isHit()) { + return null; + } + + $entry = $items[$cacheKey]->get(); + if (! $entry instanceof CacheEntry) { + return null; + } + + $result[$arrayKey] = $entry; + } + + return $result; + } + + public function put(CacheKey $key, CacheEntry $entry, Lock|null $lock = null): bool + { + $item = $this->cacheItemPool + ->getItem($this->getCacheEntryKey($key)) + ->set($entry); + + if ($this->lifetime > 0) { + $item->expiresAfter($this->lifetime); + } + + return $this->cacheItemPool->save($item); + } + + public function evict(CacheKey $key): bool + { + return $this->cacheItemPool->deleteItem($this->getCacheEntryKey($key)); + } + + public function evictAll(): bool + { + return $this->cacheItemPool->clear(self::REGION_PREFIX . $this->name); + } + + private function getCacheEntryKey(CacheKey $key): string + { + return self::REGION_PREFIX . $this->name . self::REGION_KEY_SEPARATOR . strtr($key->hash, '{}()/\@:', '________'); + } +} -- cgit v1.2.3