Home » Php » php – What is warming up a cleared cache?

php – What is warming up a cleared cache?

Posted by: admin July 12, 2020 Leave a comment


Can someone please explain in newbie words what is the meaning of warming up a cache after clearing it?

In Symfony2, there is a command that allows clearing the cache:

php app/console cache:clear

But sometimes while installing some bundles, the installation tries to clear the cache and when failed, it throws a warning saying:

Cannot clear cache with --warmup.

And why to warmup the cache after bundle installation? Your usual explanations are greatly precious.

How to&Answers:

The purpose is to initialize any cache that will be needed by the
application and prevent the first user from any significant “cache
hit” where the cache is generated dynamically.

from http://symfony.com/doc/current/reference/dic_tags.html#kernel-cache-warmer

Real world example: you give some stats that need to be cached so you can write your own service that will be called onto kernel.cache_warmer event to perform this task “statically”.


Cache warming is to generate new cache for your application. So when a user requests to open a page of your app, it can read data from the generated cache and give it back in return.

Cache cleaning is literally cleaning the old cache. If you do cache cleaning and not warming up, when a new request come, the application will do all the jobs it needs to retrieve data and to generate new cache and then return the result. If cache has been warmed up before that, then it will be directly returned, so it would be much faster response.

When installing a new bundle.. You install a new bundle to use it then in your app. So you do changes to source code like registering the bundle as a service, calling that service from your controllers for example and this kind of things. But the cache that was previously generated doesn’t know about those changes. So cache should be cleaned and generated again (warmed up) to take the changes in mind. Not a deep answer I guess, but trying to give it a simple explanation.