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] Add CachePoolClearerPass for weak cache pool refs in cache clearers#19900
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
fafff3c toc09deb5Compare| } | ||
| if (isset($attr['clearer'])) { | ||
| $clearer = $container->getDefinition($attr['clearer']); | ||
| $clearer->addMethodCall('addPool', array(new Reference($id))); |
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'd rather replace constructor argument with new one.
nicolas-grekasSep 10, 2016 • 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.
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.
This is how it is now, there is no constructor. I was about to add it, but wouldn't that enforce an unnecessary stronger binding between the actual current implementation and the way things works? Here, the only thing the code needs to know is that anaddPool method can be called. Looks a looser binding than a constructor argument to me. Given that this is not critical perf code to say the least, I think it should be kept asis.
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.
The compiler pass is already implementation-aware, becauseaddPool is not part of any interface as I can see. It's more likePsr6CacheClearerPass to be honest.
And I think it's OK for compiler pass to be locked on specific implementation, DIC is the place for this knowledge.
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.
So, what's your argument supporting the change? (you have mine :) )
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.
Given you bother withisset vsarray_key_exists performance, I wonder why you didn't take into account this one. Same kind of micro-optimization for me. :)
And yet another mutable service looks painful, just for sake of clean code.
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.
Given you bother with isset vs array_key_exists performance
I don't know how to react to this. Is it ironic? Or are you wondering why here performance is not and issue, and why it is in the container methods? I'll take the second option. A clearer is called every once in a while. On the container,get can be called thousands of times. 1000xsmall-optim == big optim. That's why it matters there.
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 just wanted to say that I see no reason to prefer setter injection over constructor one. Same level of coupling for me, better performance of constructor injection, cleaner API, less side-effects, etc.
I see that the class has no constructor, but it's not an issue to add it.
Even if somebody added his own implementation, he'd look into this source code and find out that he needs to addaddPool method or adapt constructor signature, i.e. same kind of changes. How setter is looser coupling?
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.
Even if somebody added his own implementation, he'd look into this source code and find out that he needs to add addPool
That's my point yes, and I find that having a convention that applies to a method is more open that one that applies to the constructor. That's why I said looser coupling.
Anyway, this is not directly related to this PR, which is just moving this line of code around, nothing new here.
If you really care, I propose you open a PR to change that.
c09deb5 to65dab3eCompare| /** | ||
| * @author Nicolas Grekas <p@tchwork.com> | ||
| */ | ||
| class CachePoolClearerPass implements CompilerPassInterface |
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 this class is open for inheritance (not marked asfinal)?
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.
here we are
65dab3e toce4bf44Comparece4bf44 toc4b9f7dCompare| $clearer = $container->getDefinition($attr['clearer']); | ||
| $clearer->addMethodCall('addPool', array(new Reference($id))); | ||
| } | ||
| if (array_key_exists('clearer', $attr)) { |
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 don't understand logic behind this code (array_reverse +break). Do you want to emulate overriding of the tag? Does it mean that a service cannot have 2 different clearers?
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.
cannot have 2 different clearers
True: neither in 3.1 nor with this PR. Could be worth it, I'll give it a try.
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.
But not in this PR, that's another topic :)
fabpot commentedSep 14, 2016
Thank you@nicolas-grekas. |
…che pool refs in cache clearers (nicolas-grekas)This PR was merged into the 3.2-dev branch.Discussion----------[FrameworkBundle] Add CachePoolClearerPass for weak cache pool refs in cache clearers| Q | A| ------------- | ---| Branch? | master| New feature? | yes| Tests pass? | yes| License | MITOn 3.1, when a cache pool is private and not injected anywhere, it is still added to its clearer service.The `CachePoolClearerPass` fixes this by referencing pools in clearers only after the removing passes.Commits-------c4b9f7d [FrameworkBundle] Add CachePoolClearerPass for weak cache pool refs in cache clearers
On 3.1, when a cache pool is private and not injected anywhere, it is still added to its clearer service.
The
CachePoolClearerPassfixes this by referencing pools in clearers only after the removing passes.