Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FrameworkBundle] Generate caches consistently on successive run of cache:clear command #50253

Merged
merged 1 commit into from May 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
45 changes: 23 additions & 22 deletions src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php
Expand Up @@ -137,14 +137,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
if ($output->isVerbose()) {
$io->comment('Warming up optional cache...');
}
$warmer = $kernel->getContainer()->get('cache_warmer');
// non optional warmers already ran during container compilation
$warmer->enableOnlyOptionalWarmers();
$preload = (array) $warmer->warmUp($realCacheDir);

if ($preload && file_exists($preloadFile = $realCacheDir.'/'.$kernel->getContainer()->getParameter('kernel.container_class').'.preload.php')) {
Preloader::append($preloadFile, $preload);
}
$this->warmupOptionals($realCacheDir);
}
} else {
$fs->mkdir($warmupDir);
Expand All @@ -153,7 +146,14 @@ protected function execute(InputInterface $input, OutputInterface $output): int
if ($output->isVerbose()) {
$io->comment('Warming up cache...');
}
$this->warmup($warmupDir, $realCacheDir, !$input->getOption('no-optional-warmers'));
$this->warmup($warmupDir, $realBuildDir);

if (!$input->getOption('no-optional-warmers')) {
if ($output->isVerbose()) {
$io->comment('Warming up optional cache...');
}
$this->warmupOptionals($realCacheDir);
}
}

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

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

// warmup temporary dir
if ($enableOptionalWarmers) {
$warmer = $kernel->getContainer()->get('cache_warmer');
// non optional warmers already ran during container compilation
$warmer->enableOnlyOptionalWarmers();
$preload = (array) $warmer->warmUp($warmupDir);

if ($preload && file_exists($preloadFile = $warmupDir.'/'.$kernel->getContainer()->getParameter('kernel.container_class').'.preload.php')) {
Preloader::append($preloadFile, $preload);
}
}

// fix references to cached files with the real cache directory name
$search = [$warmupDir, str_replace('\\', '\\\\', $warmupDir)];
$replace = str_replace('\\', '/', $realBuildDir);
Expand All @@ -258,4 +246,17 @@ private function warmup(string $warmupDir, string $realBuildDir, bool $enableOpt
}
}
}

private function warmupOptionals(string $realCacheDir): void
{
$kernel = $this->getApplication()->getKernel();
$warmer = $kernel->getContainer()->get('cache_warmer');
// non optional warmers already ran during container compilation
$warmer->enableOnlyOptionalWarmers();
$preload = (array) $warmer->warmUp($realCacheDir);

if ($preload && file_exists($preloadFile = $realCacheDir.'/'.$kernel->getContainer()->getParameter('kernel.container_class').'.preload.php')) {
Preloader::append($preloadFile, $preload);
}
}
}