Skip to content

Commit 3495b35

Browse files
committed
feature #21038 [FrameworkBundle] deprecated cache:clear with warmup (fabpot)
This PR was merged into the 3.3-dev branch. Discussion ---------- [FrameworkBundle] deprecated cache:clear with warmup | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | yes | Tests pass? | yes | Fixed tickets | n/a | License | MIT | Doc PR | n/a The warmup part of `cache:clear` does not work well, and does not deliver the guarantee that the generated cache is exactly the same as the one that would have been generated via `cache:warmup`. As one of the goal of Symfony 4 is to be able to generate all the cache for read-only filsystem, I propose to deprecate the warmup part of `cache:clear` in 3.3 to be able to remove it completely in 4.0. In 4.0, the `--no-warmup` option would be a noop (and can then be removed in 5.0). Commits ------- 7ed3237 [FrameworkBundle] deprecated cache:clear with warmup
2 parents 7f7b897 + 7ed3237 commit 3495b35

File tree

5 files changed

+48
-25
lines changed

5 files changed

+48
-25
lines changed

UPGRADE-3.3.md

+3
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ Finder
123123
FrameworkBundle
124124
---------------
125125

126+
* The `cache:clear` command should always be called with the `--no-warmup` option.
127+
Warmup should be done via the `cache:warmup` command.
128+
126129
* The `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddConsoleCommandPass` has been deprecated. Use `Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass` instead.
127130

128131
* The `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\SerializerPass` class has been

UPGRADE-4.0.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ EventDispatcher
124124
Use `EventDispatcher` with closure-proxy injection instead.
125125

126126
ExpressionLanguage
127-
----------
127+
------------------
128128

129129
* The ability to pass a `ParserCacheInterface` instance to the `ExpressionLanguage`
130130
class has been removed. You should use the `CacheItemPoolInterface` interface
@@ -187,6 +187,9 @@ Form
187187
FrameworkBundle
188188
---------------
189189

190+
* The `cache:clear` command does not warmup the cache anymore. Warmup should
191+
be done via the `cache:warmup` command.
192+
190193
* Support for absolute template paths has been removed.
191194

192195
* The following form types registered as services have been removed; use their

src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ CHANGELOG
44
3.3.0
55
-----
66

7+
* Deprecated `cache:clear` with warmup (always call it with `--no-warmup`)
78
* Changed default configuration for
89
assets/forms/validation/translation/serialization/csrf from `canBeEnabled()` to
910
`canBeDisabled()` when Flex is used

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

+37-24
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ protected function configure()
5454
*/
5555
protected function execute(InputInterface $input, OutputInterface $output)
5656
{
57-
$outputIsVerbose = $output->isVerbose();
5857
$io = new SymfonyStyle($input, $output);
5958

6059
$realCacheDir = $this->getContainer()->getParameter('kernel.cache_dir');
@@ -78,47 +77,59 @@ protected function execute(InputInterface $input, OutputInterface $output)
7877
if ($input->getOption('no-warmup')) {
7978
$filesystem->rename($realCacheDir, $oldCacheDir);
8079
} else {
81-
// the warmup cache dir name must have the same length than the real one
82-
// to avoid the many problems in serialized resources files
83-
$realCacheDir = realpath($realCacheDir);
84-
$warmupDir = substr($realCacheDir, 0, -1).('_' === substr($realCacheDir, -1) ? '-' : '_');
85-
86-
if ($filesystem->exists($warmupDir)) {
87-
if ($outputIsVerbose) {
88-
$io->comment('Clearing outdated warmup directory...');
89-
}
90-
$filesystem->remove($warmupDir);
91-
}
92-
93-
if ($outputIsVerbose) {
94-
$io->comment('Warming up cache...');
95-
}
96-
$this->warmup($warmupDir, $realCacheDir, !$input->getOption('no-optional-warmers'));
80+
@trigger_error('Calling cache:clear without the --no-warmup option is deprecated since version 3.3. Cache warmup should be done with the cache:warmup command instead.', E_USER_DEPRECATED);
9781

98-
$filesystem->rename($realCacheDir, $oldCacheDir);
99-
if ('\\' === DIRECTORY_SEPARATOR) {
100-
sleep(1); // workaround for Windows PHP rename bug
101-
}
102-
$filesystem->rename($warmupDir, $realCacheDir);
82+
$this->warmupCache($input, $output, $realCacheDir, $oldCacheDir);
10383
}
10484

105-
if ($outputIsVerbose) {
85+
if ($output->isVerbose()) {
10686
$io->comment('Removing old cache directory...');
10787
}
10888

10989
$filesystem->remove($oldCacheDir);
11090

111-
if ($outputIsVerbose) {
91+
if ($output->isVerbose()) {
11292
$io->comment('Finished');
11393
}
11494

11595
$io->success(sprintf('Cache for the "%s" environment (debug=%s) was successfully cleared.', $kernel->getEnvironment(), var_export($kernel->isDebug(), true)));
11696
}
11797

98+
private function warmupCache(InputInterface $input, OutputInterface $output, $realCacheDir, $oldCacheDir)
99+
{
100+
$filesystem = $this->getContainer()->get('filesystem');
101+
$io = new SymfonyStyle($input, $output);
102+
103+
// the warmup cache dir name must have the same length than the real one
104+
// to avoid the many problems in serialized resources files
105+
$realCacheDir = realpath($realCacheDir);
106+
$warmupDir = substr($realCacheDir, 0, -1).('_' === substr($realCacheDir, -1) ? '-' : '_');
107+
108+
if ($filesystem->exists($warmupDir)) {
109+
if ($output->isVerbose()) {
110+
$io->comment('Clearing outdated warmup directory...');
111+
}
112+
$filesystem->remove($warmupDir);
113+
}
114+
115+
if ($output->isVerbose()) {
116+
$io->comment('Warming up cache...');
117+
}
118+
$this->warmup($warmupDir, $realCacheDir, !$input->getOption('no-optional-warmers'));
119+
120+
$filesystem->rename($realCacheDir, $oldCacheDir);
121+
if ('\\' === DIRECTORY_SEPARATOR) {
122+
sleep(1); // workaround for Windows PHP rename bug
123+
}
124+
$filesystem->rename($warmupDir, $realCacheDir);
125+
}
126+
118127
/**
119128
* @param string $warmupDir
120129
* @param string $realCacheDir
121130
* @param bool $enableOptionalWarmers
131+
*
132+
* @internal to be removed in 4.0
122133
*/
123134
protected function warmup($warmupDir, $realCacheDir, $enableOptionalWarmers = true)
124135
{
@@ -183,6 +194,8 @@ protected function warmup($warmupDir, $realCacheDir, $enableOptionalWarmers = tr
183194
* @param string $warmupDir
184195
*
185196
* @return KernelInterface
197+
*
198+
* @internal to be removed in 4.0
186199
*/
187200
protected function getTempKernel(KernelInterface $parent, $namespace, $parentClass, $warmupDir)
188201
{

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

+3
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ protected function tearDown()
4343
$this->fs->remove($this->rootDir);
4444
}
4545

46+
/**
47+
* @group legacy
48+
*/
4649
public function testCacheIsFreshAfterCacheClearedWithWarmup()
4750
{
4851
$input = new ArrayInput(array('cache:clear'));

0 commit comments

Comments
 (0)