bug #33570 Fixed cache pools affecting each other due to an overwritten seed variable (roed)
This PR was merged into the 4.3 branch.
Discussion
----------
Fixed cache pools affecting each other due to an overwritten seed variable
| Q | A
| ------------- | ---
| Branch? | 4.3 for bug fixes
| Bug fix? | yes
| New feature? | no
| Deprecations? | no
| Tickets | Fix #33561
| License | MIT
Due to the fact the adapter was added to the cache seed calculation for cache pools, multiple pool definitions could affect each other. The how and why is described in #33561. This PR resolves that issue by using a copy of the seed and mutating only that copy.
Commits
-------
29ba7a8cf1
Fixed cache pools affecting each other due to an overwritten seed variable
This commit is contained in:
commit
4a866d066f
@ -78,11 +78,12 @@ class CachePoolPass implements CompilerPassInterface
|
|||||||
}
|
}
|
||||||
$name = $tags[0]['name'] ?? $id;
|
$name = $tags[0]['name'] ?? $id;
|
||||||
if (!isset($tags[0]['namespace'])) {
|
if (!isset($tags[0]['namespace'])) {
|
||||||
|
$namespaceSeed = $seed;
|
||||||
if (null !== $class) {
|
if (null !== $class) {
|
||||||
$seed .= '.'.$class;
|
$namespaceSeed .= '.'.$class;
|
||||||
}
|
}
|
||||||
|
|
||||||
$tags[0]['namespace'] = $this->getNamespace($seed, $name);
|
$tags[0]['namespace'] = $this->getNamespace($namespaceSeed, $name);
|
||||||
}
|
}
|
||||||
if (isset($tags[0]['clearer'])) {
|
if (isset($tags[0]['clearer'])) {
|
||||||
$clearer = $tags[0]['clearer'];
|
$clearer = $tags[0]['clearer'];
|
||||||
|
@ -70,6 +70,33 @@ class CachePoolPassTest extends TestCase
|
|||||||
$this->assertSame('xmOJ8gqF-Y', $cachePool->getArgument(0));
|
$this->assertSame('xmOJ8gqF-Y', $cachePool->getArgument(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testNamespaceArgumentIsSeededWithAdapterClassNameWithoutAffectingOtherCachePools()
|
||||||
|
{
|
||||||
|
$container = new ContainerBuilder();
|
||||||
|
$container->setParameter('kernel.container_class', 'app');
|
||||||
|
$container->setParameter('kernel.project_dir', 'foo');
|
||||||
|
$adapter = new Definition();
|
||||||
|
$adapter->setAbstract(true);
|
||||||
|
$adapter->addTag('cache.pool');
|
||||||
|
$adapter->setClass(RedisAdapter::class);
|
||||||
|
$container->setDefinition('app.cache_adapter', $adapter);
|
||||||
|
$container->setAlias('app.cache_adapter_alias', 'app.cache_adapter');
|
||||||
|
|
||||||
|
$otherCachePool = new ChildDefinition('app.cache_adapter_alias');
|
||||||
|
$otherCachePool->addArgument(null);
|
||||||
|
$otherCachePool->addTag('cache.pool');
|
||||||
|
$container->setDefinition('app.other_cache_pool', $otherCachePool);
|
||||||
|
|
||||||
|
$cachePool = new ChildDefinition('app.cache_adapter_alias');
|
||||||
|
$cachePool->addArgument(null);
|
||||||
|
$cachePool->addTag('cache.pool');
|
||||||
|
$container->setDefinition('app.cache_pool', $cachePool);
|
||||||
|
|
||||||
|
$this->cachePoolPass->process($container);
|
||||||
|
|
||||||
|
$this->assertSame('xmOJ8gqF-Y', $cachePool->getArgument(0));
|
||||||
|
}
|
||||||
|
|
||||||
public function testNamespaceArgumentIsNotReplacedIfArrayAdapterIsUsed()
|
public function testNamespaceArgumentIsNotReplacedIfArrayAdapterIsUsed()
|
||||||
{
|
{
|
||||||
$container = new ContainerBuilder();
|
$container = new ContainerBuilder();
|
||||||
|
Reference in New Issue
Block a user