Skip to content

Commit 942aab8

Browse files
bug symfony#59581 [Cache] Don't clear system caches on cache:clear (nicolas-grekas)
This PR was merged into the 6.4 branch. Discussion ---------- [Cache] Don't clear system caches on `cache:clear` | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | Fix symfony#59445 | License | MIT As spotted by `@MatTheCat` in symfony#59445 (comment), non-optional cache warmers currently cannot use any cache pools derived from the `cache.system` one. The reason is that when running `cache:clear` with no `var/cache` folder, we skip running those cache warmers since they already ran to execute the command, but we still call the cache clearer service, which empties system pools at the moment, annihilating anything non-optional cache warmers put in these pools. I propose to fix this by just not clearing cache pools derived from the system pool anymore. System pools are meant to we stored in the `kernel.cache_dir` anyway, so they're already cleared when `cache:clear` empties that folder. Commits ------- 8e82056 [Cache] Don't clear system caches on cache:clear
2 parents bb5dcc7 + 8e82056 commit 942aab8

File tree

4 files changed

+12
-21
lines changed

4 files changed

+12
-21
lines changed

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/CachePoolsTest.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,6 @@ private function doTestCachePools($options, $adapterClass)
8888
$pool2 = $container->get('cache.pool2');
8989
$pool2->save($item);
9090

91-
$container->get('cache_clearer.alias')->clear($container->getParameter('kernel.cache_dir'));
92-
$item = $pool1->getItem($key);
93-
$this->assertFalse($item->isHit());
94-
9591
$item = $pool2->getItem($key);
9692
$this->assertTrue($item->isHit());
9793

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/ContainerDebugCommandTest.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -139,14 +139,18 @@ public function testTagsPartialSearch()
139139
$tester->setInputs(['0']);
140140
$tester->run(['command' => 'debug:container', '--tag' => 'kernel.'], ['decorated' => false]);
141141

142-
$this->assertStringContainsString('Select one of the following tags to display its information', $tester->getDisplay());
143-
$this->assertStringContainsString('[0] kernel.cache_clearer', $tester->getDisplay());
144-
$this->assertStringContainsString('[1] kernel.cache_warmer', $tester->getDisplay());
145-
$this->assertStringContainsString('[2] kernel.event_subscriber', $tester->getDisplay());
146-
$this->assertStringContainsString('[3] kernel.fragment_renderer', $tester->getDisplay());
147-
$this->assertStringContainsString('[4] kernel.locale_aware', $tester->getDisplay());
148-
$this->assertStringContainsString('[5] kernel.reset', $tester->getDisplay());
149-
$this->assertStringContainsString('Symfony Container Services Tagged with "kernel.cache_clearer" Tag', $tester->getDisplay());
142+
$this->assertStringMatchesFormat(<<<EOTXT
143+
144+
Select one of the following tags to display its information:
145+
%A
146+
[%d] kernel.reset
147+
%A
148+
149+
Symfony Container Services Tagged with "kernel.%a" Tag
150+
%A
151+
EOTXT,
152+
$tester->getDisplay()
153+
);
150154
}
151155

152156
public function testDescribeEnvVars()
Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,2 @@
11
imports:
22
- { resource: ../config/default.yml }
3-
4-
services:
5-
cache_clearer.alias:
6-
alias: cache_clearer
7-
public: true

src/Symfony/Component/Cache/DependencyInjection/CachePoolPass.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,6 @@ public function process(ContainerBuilder $container)
197197
$clearer->setArgument(0, $pools);
198198
}
199199
$clearer->addTag('cache.pool.clearer');
200-
201-
if ('cache.system_clearer' === $id) {
202-
$clearer->addTag('kernel.cache_clearer');
203-
}
204200
}
205201

206202
$allPoolsKeys = array_keys($allPools);

0 commit comments

Comments
 (0)