Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[FrameworkBundle][Router][DX] Invalidate routing cache when container has changed#21443
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
sstok commentedJan 29, 2017
👍 for Being able to do this in at the router service directly is much simpler, more flexible, (and in my case) reduces the method calls for each collection. |
| if (null ===$this->collection) { | ||
| $this->collection =$this->container->get('routing.loader')->load($this->resource,$this->options['resource_type']); | ||
| $containerClassPath ="{$this->container->getParameter('kernel.cache_dir')}/{$this->container->getParameter('kernel.container_class')}.php"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
wouldn't sprintf be better here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Why not :)
nicolas-grekas commentedJan 29, 2017
why not consider this as a bug fix? |
ogizanagi commentedJan 29, 2017 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@nicolas-grekas : Mainly because it may require a new feature and it only targets a developer experience enhancement. But the current implementation is fine if we consider it a bug fix and could go to lower branches (the other implementations aren't). |
nicolas-grekas commentedJan 29, 2017
Which other implems? |
ogizanagi commentedJan 29, 2017 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Other implementations proposed in the PR description, along with@sstok's one (which is the first suggestion in PR description) 😄 But if this one if fine for everyone, let's target 2.7 as a bug fix. |
ogizanagi commentedJan 29, 2017
Rebased on 2.7 and PR description updated. |
nicolas-grekas left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
👍
fabpot commentedFeb 1, 2017
In your commit, there is a |
ogizanagi commentedFeb 1, 2017 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
This file is actually required by the test case, in order to not throw on |
ogizanagi commentedFeb 12, 2017
|
| publicstaticfunctiontearDownAfterClass() | ||
| { | ||
| (newFilesystem())->remove(static::$cachePath); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I believe this is not supported before 5.4
nicolas-grekas commentedFeb 14, 2017
Just wondering: did we try hard enough tonot invalidate when not required? It's not an issue to invalidate often - until DX is affected by the time it takes to recompile everything (routes + container). |
weaverryan commentedFeb 22, 2017
I just had a user hit this bug, so happy to see the PR! But I was also wondering the same thing as@nicolas-grekas - it's kind of a shame toalways rebuild the routing cache when the container is rebuilt, just to catch the edge case of someone modifying a parameter only. A more targeted method would be to only clear when the parameters themselves change. But, this PR is really easy because it took advantage of existing functionality (just add the container as a resource, done!). Would we be interested in only clearing when parameters change? And if so, how could we do that in some simple way? Would we need to suddenly dump some sort of parameters file separately? Could/should the framework |
ogizanagi commentedFeb 22, 2017 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Indeed, I wanted to do so, but I didn't know how to achieve it simply...yet. Another one: the
Then, the router (or anyone else) can add it as a But maybe I'm missing a more obvious way. On another hand, I'm not sure rebuilding the routing cache when the container changes would affect that much DX experience in a medium sized application. So whether or not we opt for a new feature to solve this issue more cleverly, should we merge this one to make lower branches benefits from this fix? (depending on the answers, I may open another PR on master, or replace this one) |
weaverryan commentedFeb 25, 2017
Actually, I had an idea: in This would add 2 new classes... but would fix this bug without ever unnecessarily rebuilding the routing cache. |
ogizanagi commentedFeb 25, 2017 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Indeed, that should do it and allows to track only required parameters. Or I can replace this one if you do think we should really avoid tracking the whole container on lower branches. |
ogizanagi commentedFeb 26, 2017
Closing in favor of#21767 :) |
…er parameters changed (ogizanagi)This PR was merged into the 3.3-dev branch.Discussion----------[DI][Router][DX] Invalidate routing cache when container parameters changed| Q | A| ------------- | ---| Branch? | master| Bug fix? | yes| New feature? | yes| BC breaks? | no| Deprecations? | no| Tests pass? | yes| Fixed tickets |#21426| License | MIT| Doc PR | N/ASupersedes#21443 but only for master.Indeed, this implementation uses a new feature: a `ContainerParametersResource` which compares cached containers parameters (collected at some point, here by the `Router`) with current ones in the container.On the contrary of the previous PR targeting 2.7, this will only invalidate routing cache when parameters actually used in the routes changed and will avoid always rebuilding the routing cache when the container is rebuilt, just to catch the edge case of someone modifying a parameter.Commits-------fad4d9e [DI][Router][DX] Invalidate routing cache when container parameters changed
Uh oh!
There was an error while loading.Please reload this page.
This tries tofix#21426 by adding the container class as a resource of the main
RouteCollection, allowing the router to invalidate its cache if the container has changed.There are many places & ways this could have been done:
Routerclass, by adding a router option/method to accept arbitrary resources to add.Routerclass, by adding a specificcontainer_classoption.DelegatingLoaderclass.Routerclass, directly from the container parameters (current implementation)WDYT?
I consider this as a DX enhancement rather than a real bug fix though, hence this PR targets master.