Skip to content

Commit cabc225

Browse files
committed
bug symfony#20610 [FrameworkBundle] Add framework.cache.prefix_seed for predictible cache key prefixes (nicolas-grekas)
This PR was merged into the 3.2 branch. Discussion ---------- [FrameworkBundle] Add framework.cache.prefix_seed for predictible cache key prefixes | Q | A | ------------- | --- | Branch? | 3.2 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - That's a design issue: using root_dir as discriminant doesn't work with blue/green deployment strategies, and doesn't prevent collision when different apps are deployed in the same path while sharing the same cache backend. Commits ------- 82952bd [FrameworkBundle] Add framework.cache.prefix_seed for predictible cache key prefixes
2 parents 808cc22 + 82952bd commit cabc225

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/CachePoolPass.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,12 @@ public function process(ContainerBuilder $container)
3131
{
3232
$namespaceSuffix = '';
3333

34-
foreach (array('name', 'root_dir', 'environment', 'debug') as $key) {
35-
if ($container->hasParameter('kernel.'.$key)) {
36-
$namespaceSuffix .= '.'.$container->getParameter('kernel.'.$key);
34+
foreach (array('kernel.name', 'kernel.environment', 'kernel.debug', 'cache.prefix.seed') as $key) {
35+
if ($container->hasParameter($key)) {
36+
$namespaceSuffix .= '.'.$container->getParameter($key);
3737
}
3838
}
39+
$container->getParameterBag()->remove('cache.prefix.seed');
3940

4041
$aliases = $container->getAliases();
4142
$attributes = array(

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,10 @@ private function addCacheSection(ArrayNodeDefinition $rootNode)
667667
->addDefaultsIfNotSet()
668668
->fixXmlConfig('pool')
669669
->children()
670+
->scalarNode('prefix_seed')
671+
->info('Used to namespace cache keys when using several apps with the same shared backend')
672+
->example('my-application-name')
673+
->end()
670674
->scalarNode('app')
671675
->info('App related cache pools configuration')
672676
->defaultValue('cache.adapter.filesystem')

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,6 +1242,9 @@ private function registerCacheConfiguration(array $config, ContainerBuilder $con
12421242
$container->getDefinition('cache.adapter.system')->replaceArgument(2, $version);
12431243
$container->getDefinition('cache.adapter.filesystem')->replaceArgument(2, $config['directory']);
12441244

1245+
if (isset($config['prefix_seed'])) {
1246+
$container->setParameter('cache.prefix.seed', $config['prefix_seed']);
1247+
}
12451248
foreach (array('doctrine', 'psr6', 'redis') as $name) {
12461249
if (isset($config[$name = 'default_'.$name.'_provider'])) {
12471250
$container->setAlias('cache.'.$name, Compiler\CachePoolPass::getServiceProvider($container, $config[$name]));

0 commit comments

Comments
 (0)