Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable configuration cache #19834

Closed
theofidry opened this issue Sep 2, 2016 · 9 comments

Comments

@theofidry
Copy link
Contributor

@theofidry theofidry commented Sep 2, 2016

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?

@theofidry theofidry changed the title [Cache] Add NullCacheWarmer [Cache] Disable cache Sep 2, 2016
@jameshalsall

This comment has been minimized.

Copy link
Contributor

@jameshalsall jameshalsall commented Sep 3, 2016

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

This comment has been minimized.

Copy link
Contributor Author

@theofidry theofidry commented Sep 3, 2016

@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

This comment has been minimized.

Copy link
Contributor

@jameshalsall jameshalsall commented Sep 3, 2016

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

This comment has been minimized.

Copy link
Member

@nicolas-grekas nicolas-grekas commented Sep 3, 2016

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

@theofidry

This comment has been minimized.

Copy link
Contributor Author

@theofidry theofidry commented Sep 3, 2016

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...

@theofidry theofidry changed the title [Cache] Disable cache Disable configuration cache Sep 3, 2016
@jameshalsall

This comment has been minimized.

Copy link
Contributor

@jameshalsall jameshalsall commented Sep 5, 2016

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

This comment has been minimized.

Copy link
Contributor Author

@theofidry theofidry commented Sep 5, 2016

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.

@theofidry theofidry closed this Sep 5, 2016
@ibasaw

This comment has been minimized.

Copy link

@ibasaw ibasaw commented Dec 13, 2017

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

This comment has been minimized.

Copy link

@ibasaw ibasaw commented Dec 14, 2017

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
Projects
None yet
4 participants
You can’t perform that action at this time.