From 624b98544a82b81b5d64b82110afdb9362a82891 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 17 Jan 2015 23:42:49 +0100 Subject: [PATCH] #954 DDC-2982 - `DefaultCacheFactory` now supports generic `Doctrine\Common\Cache\Cache` instances --- .../ORM/Cache/DefaultCacheFactory.php | 46 ++++++++++--------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/lib/Doctrine/ORM/Cache/DefaultCacheFactory.php b/lib/Doctrine/ORM/Cache/DefaultCacheFactory.php index c1547e52e..69d2fd1c1 100644 --- a/lib/Doctrine/ORM/Cache/DefaultCacheFactory.php +++ b/lib/Doctrine/ORM/Cache/DefaultCacheFactory.php @@ -20,26 +20,25 @@ namespace Doctrine\ORM\Cache; +use Doctrine\Common\Cache\Cache as CacheAdapter; use Doctrine\Common\Cache\CacheProvider; use Doctrine\Common\Cache\MultiGetCache; - use Doctrine\ORM\Cache; -use Doctrine\ORM\Cache\Region; -use Doctrine\ORM\Mapping\ClassMetadata; -use Doctrine\ORM\EntityManagerInterface; -use Doctrine\ORM\Cache\Region\DefaultRegion; -use Doctrine\ORM\Cache\Region\FileLockRegion; -use Doctrine\ORM\Cache\Region\UpdateTimestampCache; -use Doctrine\ORM\Cache\Region\DefaultMultiGetRegion; -use Doctrine\ORM\Cache\Persister\CachedPersister; -use Doctrine\ORM\Persisters\Entity\EntityPersister; -use Doctrine\ORM\Persisters\Collection\CollectionPersister; -use Doctrine\ORM\Cache\Persister\Entity\ReadOnlyCachedEntityPersister; -use Doctrine\ORM\Cache\Persister\Entity\ReadWriteCachedEntityPersister; +use Doctrine\ORM\Cache\Persister\Collection\NonStrictReadWriteCachedCollectionPersister; use Doctrine\ORM\Cache\Persister\Collection\ReadOnlyCachedCollectionPersister; use Doctrine\ORM\Cache\Persister\Collection\ReadWriteCachedCollectionPersister; use Doctrine\ORM\Cache\Persister\Entity\NonStrictReadWriteCachedEntityPersister; -use Doctrine\ORM\Cache\Persister\Collection\NonStrictReadWriteCachedCollectionPersister; +use Doctrine\ORM\Cache\Persister\Entity\ReadOnlyCachedEntityPersister; +use Doctrine\ORM\Cache\Persister\Entity\ReadWriteCachedEntityPersister; +use Doctrine\ORM\Cache\Region; +use Doctrine\ORM\Cache\Region\DefaultMultiGetRegion; +use Doctrine\ORM\Cache\Region\DefaultRegion; +use Doctrine\ORM\Cache\Region\FileLockRegion; +use Doctrine\ORM\Cache\Region\UpdateTimestampCache; +use Doctrine\ORM\EntityManagerInterface; +use Doctrine\ORM\Mapping\ClassMetadata; +use Doctrine\ORM\Persisters\Collection\CollectionPersister; +use Doctrine\ORM\Persisters\Entity\EntityPersister; /** * @since 2.5 @@ -48,7 +47,7 @@ use Doctrine\ORM\Cache\Persister\Collection\NonStrictReadWriteCachedCollectionPe class DefaultCacheFactory implements CacheFactory { /** - * @var \Doctrine\Common\Cache\CacheProvider + * @var CacheAdapter */ private $cache; @@ -73,10 +72,10 @@ class DefaultCacheFactory implements CacheFactory private $fileLockRegionDirectory; /** - * @param \Doctrine\ORM\Cache\RegionsConfiguration $cacheConfig - * @param \Doctrine\Common\Cache\CacheProvider $cache + * @param RegionsConfiguration $cacheConfig + * @param CacheAdapter $cache */ - public function __construct(RegionsConfiguration $cacheConfig, CacheProvider $cache) + public function __construct(RegionsConfiguration $cacheConfig, CacheAdapter $cache) { $this->cache = $cache; $this->regionsConfig = $cacheConfig; @@ -209,11 +208,16 @@ class DefaultCacheFactory implements CacheFactory $cacheAdapter = clone $this->cache; - $cacheAdapter->setNamespace($cache['region']); + if ($cacheAdapter instanceof CacheProvider) { + $cacheAdapter->setNamespace($cache['region']); + } + + $name = $cache['region']; + $lifetime = $this->regionsConfig->getLifetime($cache['region']); $region = ($cacheAdapter instanceof MultiGetCache) - ? new DefaultMultiGetRegion($cache['region'], $cacheAdapter, $this->regionsConfig->getLifetime($cache['region'])) - : new DefaultRegion($cache['region'], $cacheAdapter, $this->regionsConfig->getLifetime($cache['region'])); + ? new DefaultMultiGetRegion($name, $cacheAdapter, $lifetime) + : new DefaultRegion($name, $cacheAdapter, $lifetime); if ($cache['usage'] === ClassMetadata::CACHE_USAGE_READ_WRITE) {