-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[FrameworkBundle] Allow clearing private cache pools in cache:pool:clear #20810
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
[FrameworkBundle] Allow clearing private cache pools in cache:pool:clear #20810
Conversation
❤️ command as service |
Changing the default behavior is a BC break so not possible. Solution 1. is simplest, yet it would make sense to allow clearing any pool with the command I agree. I'd prefer a 3rd option: use the cache pool clearer service to clear by name (method to be added on it to allow so.) |
@nicolas-grekas I would like to go for your 3rd option but I believe adding this new method will be difficult since the Btw, could you please re-label this as a feature? Thanks |
Relabeling done. |
Thanks for the hints, let's see what it gives. Status: needs work |
f7db3cc
to
435f5e9
Compare
f2f4465
to
54ee65b
Compare
I added Status: needs review |
54ee65b
to
e7bd1c3
Compare
12d7fda
to
d38ca9d
Compare
@nicolas-grekas changes done, I think we are almost good here |
$this->pools[] = $pool; | ||
@trigger_error(sprintf('The %s() method is deprecated since version 3.3 and will be removed in 4.0. Pass an array of pools indexed by name to the constructor instead.', __METHOD__), E_USER_DEPRECATED); | ||
|
||
if (!in_array($pool, $this->pools, true)) { |
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 block is unrelated to the feature of the PR, should be removed
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.
It's about keeping BC. If someone rely on addPool()
, the pool should still be cleared when calling clear()
, right? The use of in_array
is to avoid registering the same pool twice in this case. Maybe you've a better one?
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 wouldn't care much: either people use the new way, or the deprecated one. We don't have to handle people doing both IMO.
throw new \InvalidArgumentException(sprintf('Cache pool not found: %s.', $name)); | ||
} | ||
|
||
$this->pools[$name]->clear(); |
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.
fir the shake of completeness: return $this->pools[$name]->clear();
if ($pool instanceof CacheItemPoolInterface) { | ||
$pool->clear(); | ||
} else { | ||
$globalClearer->clearPool($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.
Now I understand why you needed hasPool :)
This can throw in the middle of a clean because of a missing pool.
Then I propose to replace clearPool($pool) by PsrCacheClearer::getPools()
and handle validation with the resulting array.
WDYT?
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.
Either we keep hasPool()/clearPool()
or we get all the pools and let the caller doing the filtering logic as you propose, it's debatable but I would prefer keep the clearer being a clearer rather than an accessor. As you prefer :)
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.
let's go for hasPool :)
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.
done!
d38ca9d
to
7522dcf
Compare
👍 |
daac4e8
to
6b94068
Compare
6b94068
to
b71df3f
Compare
Either |
Indeed. Forgot about the fact tags are not inherited anyway when using a parent definition. 👍 |
However, I found it confusing to reuse the same class for the global cache clearing, even if it's not wired as a kernel cache clearer. What were the arguments against a dedicated |
There's no need for accessing pools but only clearing them and like this we can keep pools really private (not accessible from a public service). |
Ok. Let's move forward. 👍 |
Thank you @chalasr. |
…n cache:pool:clear (chalasr) This PR was merged into the 3.3-dev branch. Discussion ---------- [FrameworkBundle] Allow clearing private cache pools in cache:pool:clear | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | n/a | License | MIT | Doc PR | n/a In a2a567d cache pools have been passed to `public: false` by default. The problem is that in 3.2 the `cache:pool:clear` command has been introduced and uses `Container::get($pool);` for clearing them, but the service can't be found since it is private. So I propose to add a global clearer being able to clear any pool. Commits ------- b71df3f [FrameworkBundle] Allow clearing private cache pools
…asr) This PR was merged into the 3.3-dev branch. Discussion ---------- [HttpKernel] Fix missing psr/cache dev requirement | Q | A | ------------- | --- | Branch? | master | Bug fix? | yes, tests are broken | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | n/a | License | MIT | Doc PR | n/a Because #20810 added a test for the `Psr6CacheClearer` that mocks methods of the `CacheItemPoolInterface`. It should fix the travis build on master and deps=low Commits ------- bd59d75 [HttpKernel] Require psr/cache in dev
Maybe that this PR breaks tests on master (https://travis-ci.org/symfony/symfony/jobs/183706820) but I don't get exactly what happens (I cannot reproduce in local). |
In a2a567d cache pools have been passed to
public: false
by default.The problem is that in 3.2 the
cache:pool:clear
command has been introduced and usesContainer::get($pool);
for clearing them, but the service can't be found since it is private.So I propose to add a global clearer being able to clear any pool.