1
0
mirror of synced 2025-02-10 01:09:26 +03:00

Merge pull request #6223 from lcobucci/fix-l2c-region-namespace

Appends cache namespace when it exists (for L2C regions)
This commit is contained in:
Marco Pivetta 2017-01-11 11:33:41 +01:00 committed by GitHub
commit 4e304df495
2 changed files with 102 additions and 59 deletions

View File

@ -200,13 +200,8 @@ class DefaultCacheFactory implements CacheFactory
return $this->regions[$cache['region']];
}
$cacheAdapter = clone $this->cache;
if ($cacheAdapter instanceof CacheProvider) {
$cacheAdapter->setNamespace($cache['region']);
}
$name = $cache['region'];
$cacheAdapter = $this->createRegionCache($name);
$lifetime = $this->regionsConfig->getLifetime($cache['region']);
$region = ($cacheAdapter instanceof MultiGetCache)
@ -229,6 +224,30 @@ class DefaultCacheFactory implements CacheFactory
return $this->regions[$cache['region']] = $region;
}
/**
* @param string $name
*
* @return CacheAdapter
*/
private function createRegionCache($name)
{
$cacheAdapter = clone $this->cache;
if (!$cacheAdapter instanceof CacheProvider) {
return $cacheAdapter;
}
$namespace = $cacheAdapter->getNamespace();
if ('' !== $namespace) {
$namespace .= ':';
}
$cacheAdapter->setNamespace($namespace . $name);
return $cacheAdapter;
}
/**
* {@inheritdoc}
*/

View File

@ -296,6 +296,30 @@ class DefaultCacheFactoryTest extends OrmTestCase
$this->assertSame('bar', $barRegion->getCache()->getNamespace());
}
public function testAppendsNamespacedCacheInstancePerRegionInstanceWhenItsAlreadySet()
{
$cache = clone $this->getSharedSecondLevelCacheDriverImpl();
$cache->setNamespace('testing');
$factory = new DefaultCacheFactory($this->regionsConfig, $cache);
$fooRegion = $factory->getRegion(
[
'region' => 'foo',
'usage' => ClassMetadata::CACHE_USAGE_READ_ONLY,
]
);
$barRegion = $factory->getRegion(
[
'region' => 'bar',
'usage' => ClassMetadata::CACHE_USAGE_READ_ONLY,
]
);
$this->assertSame('testing:foo', $fooRegion->getCache()->getNamespace());
$this->assertSame('testing:bar', $barRegion->getCache()->getNamespace());
}
public function testBuildsDefaultCacheRegionFromGenericCacheRegion()
{
/* @var $cache \Doctrine\Common\Cache\Cache */