1
0
mirror of synced 2025-02-02 21:41:45 +03:00

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:
Luís Cobucci 2017-01-11 10:40:23 +01:00
parent 4e573038be
commit 5a562b3571
No known key found for this signature in database
GPG Key ID: 8042585A7DBC92E1
2 changed files with 51 additions and 8 deletions

View File

@ -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}
*/

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 */