Merge pull request #1259 from Ocramius/hotfix/cache-region-cache-namespace-mutability-removal
Hotfix: Cache region should not mutate injected cache instance settings
This commit is contained in:
commit
f97bb00dff
@ -198,7 +198,11 @@ class DefaultCacheFactory implements CacheFactory
|
||||
return $this->regions[$cache['region']];
|
||||
}
|
||||
|
||||
$region = new DefaultRegion($cache['region'], clone $this->cache, $this->regionsConfig->getLifetime($cache['region']));
|
||||
$cacheAdapter = clone $this->cache;
|
||||
|
||||
$cacheAdapter->setNamespace($cache['region']);
|
||||
|
||||
$region = new DefaultRegion($cache['region'], $cacheAdapter, $this->regionsConfig->getLifetime($cache['region']));
|
||||
|
||||
if ($cache['usage'] === ClassMetadata::CACHE_USAGE_READ_WRITE) {
|
||||
|
||||
|
@ -59,8 +59,6 @@ class DefaultRegion implements Region
|
||||
$this->cache = $cache;
|
||||
$this->name = (string) $name;
|
||||
$this->lifetime = (integer) $lifetime;
|
||||
|
||||
$this->cache->setNamespace($this->name);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -257,11 +257,28 @@ class DefaultCacheFactoryTest extends OrmTestCase
|
||||
*/
|
||||
public function testInvalidFileLockRegionDirectoryException()
|
||||
{
|
||||
$factory = new \Doctrine\ORM\Cache\DefaultCacheFactory($this->regionsConfig, $this->getSharedSecondLevelCacheDriverImpl());
|
||||
$factory = new DefaultCacheFactory($this->regionsConfig, $this->getSharedSecondLevelCacheDriverImpl());
|
||||
|
||||
$factory->getRegion(array(
|
||||
'usage' => ClassMetadata::CACHE_USAGE_READ_WRITE,
|
||||
'region' => 'foo'
|
||||
));
|
||||
}
|
||||
|
||||
public function testBuildsNewNamespacedCacheInstancePerRegionInstance()
|
||||
{
|
||||
$factory = new DefaultCacheFactory($this->regionsConfig, $this->getSharedSecondLevelCacheDriverImpl());
|
||||
|
||||
$fooRegion = $factory->getRegion(array(
|
||||
'region' => 'foo',
|
||||
'usage' => ClassMetadata::CACHE_USAGE_READ_ONLY,
|
||||
));
|
||||
$barRegion = $factory->getRegion(array(
|
||||
'region' => 'bar',
|
||||
'usage' => ClassMetadata::CACHE_USAGE_READ_ONLY,
|
||||
));
|
||||
|
||||
$this->assertSame('foo', $fooRegion->getCache()->getNamespace());
|
||||
$this->assertSame('bar', $barRegion->getCache()->getNamespace());
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace Doctrine\Tests\ORM\Cache;
|
||||
|
||||
use Doctrine\Common\Cache\ArrayCache;
|
||||
use Doctrine\ORM\Cache\Region\DefaultRegion;
|
||||
use Doctrine\Tests\Mocks\CacheEntryMock;
|
||||
use Doctrine\Tests\Mocks\CacheKeyMock;
|
||||
@ -47,4 +48,16 @@ class DefaultRegionTest extends AbstractRegionTest
|
||||
$this->assertFalse($region1->contains($key));
|
||||
$this->assertTrue($region2->contains($key));
|
||||
}
|
||||
|
||||
public function testDoesNotModifyCacheNamespace()
|
||||
{
|
||||
$cache = new ArrayCache();
|
||||
|
||||
$cache->setNamespace('foo');
|
||||
|
||||
new DefaultRegion('bar', $cache);
|
||||
new DefaultRegion('baz', $cache);
|
||||
|
||||
$this->assertSame('foo', $cache->getNamespace());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user