S
S
Stanislav2019-10-30 19:51:59
symfony
Stanislav, 2019-10-30 19:51:59

Symfony 4: how to disable caching of classes and stuff in var/cache?

Actually, the topic is the whole question. It is necessary in order to debug the code without problems, otherwise when a request comes in and we fall into this cache, this causes problems. Interested in such a method that would allow this to be done at the stage of a running application, in other words, in the public/index.php file. Well, it would be great as a bonus if you briefly tell what it is and why, or at least give a link with an explanation for dummies about this cache.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
BoShurik, 2019-10-31
@lamo4ok

You should not turn it off, because. container and routing compiled by design, i.e. the response time will be very long (4000ms vs 250ms on my application)
If you really want, you can do this:

// \App\Kernel
protected function initializeContainer()
{
    if ($_ENV['APP_ENV'] === 'dev') {
        $container = $this->buildContainer();
        $container->setParameter('container.build_id', 'id');
        $container->setParameter('container.build_hash', 'hash');
        $container->set('kernel', $this);
        $container->compile(true);

        $this->container = $container;
    } else {
        parent::initializeContainer();
    }
}

But to make it work, I had to disable smart-core/accelerator-cache-bundle, maybe other bundles are also incompatible with this mode.
So in your case, I would still recommend configuring the docker somehow.

D
Daria Motorina, 2019-10-30
@glaphire

In the dev environment, the cache is regenerated for every change in the affected code, emnip. The container is cached to save resources when generating such a rather complex class. The rest of the cache by analogy - to save resources.
https://symfony.com/doc/current/components/depend...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question