Search code examples
cachingsymfony

How Symfony configuration cache works?


I want to know how symfony cache works especially for the configuration of my app (doctrine connexion parameter , etc ...)

I guess he works like this : read once config.yml file and cache it. Is this true ?

Can I apply a lifetime on it? or I need to execute php bin/console cache:clear?


Solution

  • It's a bit more complicated than that, and depends a bit on which files we are talking about.

    Specifically, config.yml and related files are used to configure the service container. These files are parsed by the kernel to compile the service container definition. The resulting container is then cached as a PHP class/file in the cache directory.

    By default, Symfony will automatically pick up any changes to the service container configuration and recompile the container when necessary for the development environment. For production environment however, you need to manually clear the cache to rebuild the container.