Skip to content

Disable configuration cache #19834

Closed
Closed
@theofidry

Description

@theofidry
Contributor

As of now, a cache warmer is always used. Unlike some other components like the serializer, the cache cannot be completely disabled via the configuration.

In my case for example, I'm loading a kernel with different configuration files, i.e. I must make sure the configuration is not cached between each loading. As I hardly see anyone who would want to disable cache to the point of not caching the configuration, rather than adding a config parameter I would rather be up for adding a NoCacheKernel class (in which initializeContainer() is overridden to always use a fresh config), available as a test class like KernelTestCase.

WDYT?

Activity

changed the title [-][Cache] Add NullCacheWarmer[/-] [+][Cache] Disable cache[/+] on Sep 2, 2016
jameshalsall

jameshalsall commented on Sep 3, 2016

@jameshalsall
Contributor

I'm unsure what you are asking? You can create your own NoCacheKernel in app/ (in the symfony-standard edition) and override the initializeContainer() method like you said.

theofidry

theofidry commented on Sep 3, 2016

@theofidry
ContributorAuthor

@jameshalsall I'm basically asking to have something like that in Symfony core as we have something like KernelTestCase.

That said I tried to do that:

protected function initializeContainer()
    {
        $class = $this->getContainerClass();
        $cache = new ConfigCache($this->getCacheDir().'/'.$class.'.php', $this->debug);
        $container = $this->buildContainer();
        $container->compile();
        $this->dumpContainer($cache, $container, $class, $this->getContainerBaseClass());

        require_once $cache->getPath();

        $this->container = new $class();
        $this->container->set('kernel', $this);
    }

(it's the same as the parent with fresh always at true), yet this does not work: from one test to another with a different configuration, I get the wrong config at the end. The config is correctly loaded (the right file), but somehow I get the previous config in the end. I can see that because one of my bundle injects the configuration parameters to the parameter bag and I'm getting the wrong values.

The whole AppKernel can be found here and the bundle I'm referring to is here.

jameshalsall

jameshalsall commented on Sep 3, 2016

@jameshalsall
Contributor

I don't understand what you mean by "the config is loaded correctly, but somehow I get the previous config at the end"?

nicolas-grekas

nicolas-grekas commented on Sep 3, 2016

@nicolas-grekas
Member

Just for correct triage, this is related to FrameworkBundle, not to the Cache component, isn't it?

theofidry

theofidry commented on Sep 3, 2016

@theofidry
ContributorAuthor

I have one config file with "nothing" it it, i.e. with the default values for my bundle configuration (they are all optional). And I have another config file with different values from the default one. In my extension, I'm injecting those configuration values into the container.

In my test cases, sometimes I'm loading a kernel loaded with the regular config file, another time with the other. Each time I shutdown and boot the kernel properly, each test individually pass. Yet if I run the whole testsuite my test fails because I get the wrong parameters.

@nicolas-grekas yes indeed sorry about that, I first though it was related to the cache warmer and I wanted to register a NullCacheWarmer...

changed the title [-][Cache] Disable cache[/-] [+]Disable configuration cache[/+] on Sep 3, 2016
jameshalsall

jameshalsall commented on Sep 5, 2016

@jameshalsall
Contributor

In my test cases, sometimes I'm loading a kernel loaded with the regular config file, another time with the other. Each time I shutdown and boot the kernel properly, each test individually pass. Yet if I run the whole testsuite my test fails because I get the wrong parameters.

I think that answers your question, you need to boot a new Kernel when new configuration should be loaded. Once the config is loaded when the Kernel is booted it will not try to load configuration again as it is stored in memory.

theofidry

theofidry commented on Sep 5, 2016

@theofidry
ContributorAuthor

Indeed, and so the easiest way to solve that is to generate a Kernel with a different environment each time. Thanks for the tip @jameshalsall :)

Maybe this should be documented somewhere, but not really sure were it would be the appropriate place for that.

ibasaw

ibasaw commented on Dec 13, 2017

@ibasaw

need same thing...but don't know how to do it.

i try to do a multi domain website on same code, all change with the domain url.

i got a parameter.php file, inside this file, i define some parameters by domain.

I got a problem with the cache, the configuration is only the first time run, because it read again in the cache.

How to disable cache for parameters.php ?

@theofidry : how did you solved your problem ?

ibasaw

ibasaw commented on Dec 14, 2017

@ibasaw

found it ! i use an array and pass it to the kernel, in the kernel i set up different cache dir depends on the array configuration

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @nicolas-grekas@ibasaw@jameshalsall@theofidry

        Issue actions

          Disable configuration cache · Issue #19834 · symfony/symfony