Symfony 4 was released on November 30th.
Update now to the best Symfony ever!

New in Symfony 3.3: Deprecated cache clear with warmup

Contributed by
Fabien Potencier
in #21038.

Symfony applications generate some cache files before running for the first time to improve their performance (for example to transform the Twig templates and the XML/YAML/Annotations configuration into PHP code).

These cached files are generated during a process called "cache warmup". Symfony includes lots of "cache warmers" (for routing, templates, configuration, Doctrine, etc.) and your application can define custom "cache warmers" by creating a class implementing Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface and defining a service for it with the kernel.cache_warmer tag.

Symfony's FrameworkBundle provides two commands to warmup the cache:

1
2
3
4
5
6
7
8
# warmup the existing cache but don't clear it
$ ./bin/console cache:warmup (--env=prod|dev)

# clear the existing cache and warm it up
$ ./bin/console cache:clear (--env=prod|dev)

# clear the existing cache but don't warm it up
$ ./bin/console cache:clear --no-warmup (--env=prod|dev)

However, the warmup part of the cache:clear command 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.

Since one of the main goals of Symfony 4 is to be able to generate the full cache to allow executing the application on read-only filesystems, we've decided to deprecate the warmup part of cache:clear in Symfony 3.3 and remove it completely in Symfony 4.0.

In practice, this means that you should always add the --no-warmup option to the cache:clear command and then execute cache:warmup:

1
2
3
4
5
6
# before
$ ./bin/console cache:clear (--env=prod|dev)

# after
$ ./bin/console cache:clear --no-warmup (--env=prod|dev)
$ ./bin/console cache:warmup (--env=prod|dev)

Comments

"warmup it" could be replaced by and "warm it up" to be more correct ;)
By the way, I think it's a nice idea, because cache clear is sometimes long because of warmup systematic execution, so it's nice that it's removed from cache:clear :)
Can anyone explain the differences between the two methods of warming up?
@Alex thanks for the heads up! It's fixed now.
Can anybody point to some issues with "cache:clear" now warming up properly?
If I change the configuration of a running application, than "cache:clear" with warmup was very useful, because it first creates a shadow cache (based on the new configuration) before deleting the cache. So the switch was an atomic operation. Would this also possible with the new command?
Is this also going to be changed on "\Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache" ?

Comments are closed.

To ensure that comments stay relevant, they are closed for old posts.