From f4b9635e3ca378c2fb0d10982768e825281568fd Mon Sep 17 00:00:00 2001 From: Tobias Schultze Date: Fri, 14 Feb 2020 17:09:07 +0100 Subject: [PATCH] [Cache] fix sharing cache between apps The configurable cache prefix seed does not give full control over the cache prefix because the container class is added to the prefix in any case. This is a problem because the container class contains the app env name. We use different app environments for different deployment targets (dev and test). Dev and test should use the same redis cache. But this is impossible to achieve because even setting the cache prefix seed does not accomplish this. --- .../Tests/DependencyInjection/Compiler/CachePoolPassTest.php | 4 ++-- .../Tests/DependencyInjection/FrameworkExtensionTest.php | 4 ++-- .../Component/Cache/DependencyInjection/CachePoolPass.php | 2 +- .../Cache/Tests/DependencyInjection/CachePoolPassTest.php | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/CachePoolPassTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/CachePoolPassTest.php index 6bc90a478fd56..cb9df10dcfdb3 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/CachePoolPassTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/CachePoolPassTest.php @@ -87,7 +87,7 @@ public function testArgsAreReplaced() $this->assertInstanceOf(Reference::class, $cachePool->getArgument(0)); $this->assertSame('foobar', (string) $cachePool->getArgument(0)); - $this->assertSame('tQNhcV-8xa', $cachePool->getArgument(1)); + $this->assertSame('croSeNd5bG', $cachePool->getArgument(1)); $this->assertSame(3, $cachePool->getArgument(2)); } @@ -108,7 +108,7 @@ public function testWithNameAttribute() $this->cachePoolPass->process($container); - $this->assertSame('+naTpPa4Sm', $cachePool->getArgument(1)); + $this->assertSame('-Tv17ISg7e', $cachePool->getArgument(1)); } public function testThrowsExceptionWhenCachePoolTagHasUnknownAttributes() diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php index b65ab9e011f28..efcecb3cf95a5 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php @@ -1457,11 +1457,11 @@ public function testCachePoolServices() (new ChildDefinition('cache.adapter.array')) ->replaceArgument(0, 12), (new ChildDefinition('cache.adapter.filesystem')) - ->replaceArgument(0, 'xctxZ1lyiH') + ->replaceArgument(0, 'kByObfHfz6') ->replaceArgument(1, 12), (new ChildDefinition('cache.adapter.redis')) ->replaceArgument(0, new Reference('.cache_connection.kYdiLgf')) - ->replaceArgument(1, 'xctxZ1lyiH') + ->replaceArgument(1, 'kByObfHfz6') ->replaceArgument(2, 12), ], 12, diff --git a/src/Symfony/Component/Cache/DependencyInjection/CachePoolPass.php b/src/Symfony/Component/Cache/DependencyInjection/CachePoolPass.php index f52d0271e4117..9e14a93a12d6e 100644 --- a/src/Symfony/Component/Cache/DependencyInjection/CachePoolPass.php +++ b/src/Symfony/Component/Cache/DependencyInjection/CachePoolPass.php @@ -52,8 +52,8 @@ public function process(ContainerBuilder $container) $seed = '.'.$container->getParameterBag()->resolveValue($container->getParameter('cache.prefix.seed')); } else { $seed = '_'.$container->getParameter('kernel.project_dir'); + $seed .= '.'.$container->getParameter('kernel.container_class'); } - $seed .= '.'.$container->getParameter('kernel.container_class'); $allPools = []; $clearers = []; diff --git a/src/Symfony/Component/Cache/Tests/DependencyInjection/CachePoolPassTest.php b/src/Symfony/Component/Cache/Tests/DependencyInjection/CachePoolPassTest.php index 20701adcb4507..94b8b43c42027 100644 --- a/src/Symfony/Component/Cache/Tests/DependencyInjection/CachePoolPassTest.php +++ b/src/Symfony/Component/Cache/Tests/DependencyInjection/CachePoolPassTest.php @@ -135,7 +135,7 @@ public function testArgsAreReplaced() $this->assertInstanceOf(Reference::class, $cachePool->getArgument(0)); $this->assertSame('foobar', (string) $cachePool->getArgument(0)); - $this->assertSame('tQNhcV-8xa', $cachePool->getArgument(1)); + $this->assertSame('croSeNd5bG', $cachePool->getArgument(1)); $this->assertSame(3, $cachePool->getArgument(2)); } @@ -156,7 +156,7 @@ public function testWithNameAttribute() $this->cachePoolPass->process($container); - $this->assertSame('+naTpPa4Sm', $cachePool->getArgument(1)); + $this->assertSame('-Tv17ISg7e', $cachePool->getArgument(1)); } public function testThrowsExceptionWhenCachePoolTagHasUnknownAttributes()