8000 [FrameworkBundle] Generate caches consistently on successive run of `… · symfony/symfony@dcbdca6 · GitHub
[go: up one dir, main page]

Skip to content

Commit dcbdca6

Browse files
Okhoshinicolas-grekas
authored andcommitted
[FrameworkBundle] Generate caches consistently on successive run of cache:clear command
1 parent d61b959 commit dcbdca6

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