1
0
mirror of synced 2024-12-05 03:06:05 +03:00

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:
Fabio B. Silva 2015-01-15 15:26:23 -05:00
commit f97bb00dff
4 changed files with 36 additions and 4 deletions

View File

@ -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) {

View File

@ -59,8 +59,6 @@ class DefaultRegion implements Region
$this->cache = $cache;
$this->name = (string) $name;
$this->lifetime = (integer) $lifetime;
$this->cache->setNamespace($this->name);
}
/**

View File

@ -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());
}
}

View File

@ -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());
}
}