8000 bug #50253 [FrameworkBundle] Generate caches consistently on successi… · symfony/symfony@6166fc4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6166fc4

Browse files
bug #50253 [FrameworkBundle] Generate caches consistently on successive run of cache:clear command (Okhoshi)
This PR was submitted for the 6.2 branch but it was merged into the 5.4 branch instead. Discussion ---------- [FrameworkBundle] Generate caches consistently on successive run of `cache:clear` command | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #46324 | License | MIT | Doc PR | N/A When the Kernel is configured to use different directories for `build_dir` and `cache_dir`, successive runs of the `cache:clear` produce different outputs. See #46324 for the reproduction steps and the differences observed. This is due to the fact that if the cached kernel needs to be regenerated when invoking `cache:clear` command, the cache warmers are run in the same directory where the kernel was regenerated (`$warmupDir`, which will become the `build_dir`). When the cache is fresh, only cache warmers are run, and in `cache_dir` this time. Commits ------- dcbdca6 [FrameworkBundle] Generate caches consistently on successive run of `cache:clear` command
2 parents d61b959 + dcbdca6 commit 6166fc4

File tree

1 file changed

+23
-22
lines changed

1 file changed

+23
-22
lines changed

src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
137137
if ($output->isVerbose()) {
138138
$io->comment('Warming up optional cache...');
139139
}
140-
$warmer = $kernel->getContainer()->get('cache_warmer');
141-
// non optional warmers already ran during container compilation
142-
$warmer->enableOnlyOptionalWarmers();
143-
$preload = (array) $warmer->warmUp($realCacheDir);
144-
145-
if ($preload && file_exists($preloadFile = $realCacheDir.'/'.$kernel->getContainer()->getParameter('kernel.container_class').'.preload.php')) {
146-
Preloader::append($preloadFile, $preload);
147-
}
140+
$this->warmupOptionals($realCacheDir);
148141
}
149142
} else {
150143
$fs->mkdir($warmupDir);
@@ -153,7 +146,14 @@ protected function execute(InputInterface $input, OutputInterface $output): int
153146
if ($output->isVerbose()) {
154147
$io->comment('Warming up cache...');
155148
}
156-
$this->warmup($warmupDir, $realCacheDir, !$input->getOption('no-optional-warmers'));
149+
$this->warmup($warmupDir, $realBuildDir);
150+
151+
if (!$input->getOption('no-optional-warmers')) {
152+
if ($output->isVerbose()) {
153+
$io->comment('Warming up optional cache...');
154+
}
155+
$this->warmupOptionals($realCacheDir);
156+
}
157157
}
158158

159159
if (!$fs->exists($warmupDir.'/'.$containerDir)) {
@@ -227,7 +227,7 @@ private function isNfs(string $dir): bool
227227
return false;
228228
}
229229

230-
private function warmup(string $warmupDir, string $realBuildDir, bool $enableOptionalWarmers = true)
230+
private function warmup(string $warmupDir, string $realBuildDir): void
231231
{
232232
// create a temporary kernel
233233
$kernel = $this->getApplication()->getKernel();
@@ -236,18 +236,6 @@ private function warmup(string $warmupDir, string $realBuildDir, bool $enableOpt
236236
}
237237
$kernel->reboot($warmupDir);
238238

239-
// warmup temporary dir
240-
if ($enableOptionalWarmers) {
241-
$warmer = $kernel->getContainer()->get('cache_warmer');
242-
// non optional warmers already ran during container compilation
243-
$warmer->enableOnlyOptionalWarmers();
244-
$preload = (array) $warmer->warmUp($warmupDir);
245-
246-
if ($preload && file_exists($preloadFile = $warmupDir.'/'.$kernel->getContainer()->getParameter('kernel.container_class').'.preload.php')) {
247-
Preloader::append($preloadFile, $preload);
248-
}
249-
}
250-
251239
// fix references to cached files with the real cache directory name
252240
$search = [$warmupDir, str_replace('\\', '\\\\', $warmupDir)];
253241
$replace = str_replace('\\', '/', $realBuildDir);
@@ -258,4 +246,17 @@ private function warmup(string $warmupDir, string $realBuildDir, bool $enableOpt
258246
}
259247
}
260248
}
249+
250+
private function warmupOptionals(string $realCacheDir): void
251+
{
252+
$kernel = $this->getApplication()->getKernel();
253+
$warmer = $kernel->getContainer()->get('cache_warmer');
254+
// non optional warmers already ran during container compilation
255+
$warmer->enableOnlyOptionalWarmers();
256+
$preload = (array) $warmer->warmUp($realCacheDir);
257+
258+
if ($preload && file_exists($preloadFile = $realCacheDir.'/'.$kernel->getContainer()->getParameter('kernel.container_class').'.preload.php')) {
259+
Preloader::append($preloadFile, $preload);
260+
}
261+
}
261262
}

0 commit comments

Comments
 (0)
0