Appends cache namespace when it exists (for L2C regions)
We're overriding the namespace without even checking if it was previously
set, what causes problems when people uses that feature 😉
This commit is contained in:
parent
4e573038be
commit
5a562b3571
@ -200,14 +200,9 @@ class DefaultCacheFactory implements CacheFactory
|
||||
return $this->regions[$cache['region']];
|
||||
}
|
||||
|
||||
$cacheAdapter = clone $this->cache;
|
||||
|
||||
if ($cacheAdapter instanceof CacheProvider) {
|
||||
$cacheAdapter->setNamespace($cache['region']);
|
||||
}
|
||||
|
||||
$name = $cache['region'];
|
||||
$lifetime = $this->regionsConfig->getLifetime($cache['region']);
|
||||
$name = $cache['region'];
|
||||
$cacheAdapter = $this->createRegionCache($name);
|
||||
$lifetime = $this->regionsConfig->getLifetime($cache['region']);
|
||||
|
||||
$region = ($cacheAdapter instanceof MultiGetCache)
|
||||
? new DefaultMultiGetRegion($name, $cacheAdapter, $lifetime)
|
||||
@ -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}
|
||||
*/
|
||||
|
@ -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 */
|
||||
|
Loading…
x
Reference in New Issue
Block a user