-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Cache] Use namespace versioning for backends that dont support clearing by keys #23969
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
Conversation
d33fc54
to
c15d72e
Compare
@@ -189,11 +204,18 @@ private function getId($key) | |||
{ | |||
CacheItem::validateKey($key); | |||
|
|||
if ($this->versioningIsEnabled && '' === $this->namespaceVersion) { |
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.
Other classes used the trick isset($string[0])
to check if their is a namespace.
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.
not sure it applies here
c15d72e
to
63b5154
Compare
with new false positive from php-cs-fixer... |
63b5154
to
025be26
Compare
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.
Looks good!
Although I'm wondering why you put a colon after the namespace while colons are not allowed in validateKey?
(We used to use colons in our cache keys until we switched to the new classes which don't allow it ;)
Also on a side note: Is there any reason why an integer is not allowed as cache key if it gets namespaced anyway? We have/had that, unfortunately.)
I put a colon because they are not allowed when given from the outside. Here, we're past the interface, so the PSR-6/16 constraints do not apply. Which is very nice for us: using a colon makes it impossible to have any confusion with user input.
because PSR-6/16 states that a key must be a string. So |
025be26
to
b245adc
Compare
I'm a bit torn on this, as it adds extra lookup for every lookup. Would it be possible to rather do this on first usage, and afterwards get it using multi get together with the item lookup? Then if version has changed either refetch the items, or in future when there is stale cache support on get we can still return the items when callee indicated it does not need fresh items, however have the new version set for next caller. If that won't fly, then at least make sure this is only done once on multi get lookus. in current patch here it will be done for every key before lookup on all is done, which I would consider a bug. |
As the PR is now, the version retrieval is done only once, on first need. That's how Doctrine does it also afaik. Isn't it good enough? |
Ah, sorry missed that completely. It's fine with me, but you can bet there will be bug report for this down the line for long running processes :) |
b245adc
to
f8a7518
Compare
so, I added a public method to explicitly reset the memoized version, for the long running process use case. This looks much more reasonable to me than fetching the key on every fetch, as even multi-fetch are not always grouped (eg RedisCluster or RedisArray), thus would pay an extra cost at each fetch. This requires long running processes to do something like that in their main loop: Yes, this is a "new feature" (because a new public method is). Yet, it is required to compensate for a behavior change (long running process don't have their cache cleared anymore). And the behavior change is also technically a BC break. Yet also I think this is a really edge-case one and the issue is at the design level so that it cannot be solved otherwise. |
A use case for such each case would be to implement a reverse proxy base on ReactPHP (php-pm for instance). With cache invalidation with the clear method. |
Yes, ReactPHP or similar will hit this. But I agree with @nicolas-grekas that main usage should not pay a penalty because of it. One option would be to clearly document handlers/ connection classes that don't support flushing pool and hence not recommended for use with long running php processes such as ReactPHP/cron/script. |
well, with this patch, all handlers do support flushing. But for long running processes, the concern leaks, and I have no better reasonable idea to make it not. So, we would require ppl to call |
Thank you @nicolas-grekas. |
…pport clearing by keys (nicolas-grekas) This PR was merged into the 3.3 branch. Discussion ---------- [Cache] Use namespace versioning for backends that dont support clearing by keys | Q | A | ------------- | --- | Branch? | 3.3 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #23960 | License | MIT | Doc PR | - Commits ------- f8a7518 [Cache] Use namespace versioning for backends that dont support clearing by keys
* When versioning is enabled, clearing the cache is atomic and doesn't require listing existing keys to proceed, | ||
* but old keys may need garbage collection and extra round-trips to the back-end are required. | ||
* | ||
* Calling this method also clears the memoized namespace version and thus forces a resynchonization of it. |
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.
@nicolas-grekas Spelling errors: "memoized" -> "memorized" and "resynchonization" -> "resynchronization"
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 reported the "memoized" typo once ... and I was wrong :( "Memoize" seems to be a valid concept: https://en.wikipedia.org/wiki/Memoization Maybe it's used correctly this time too?
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.
Ah; seems you are correct! I think the latter one is a spelling error though. ;-)
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 wrote memoize on purpose :)
…k component (jderusse) This PR was submitted for the 3.4 branch but it was merged into the 3.3 branch instead (closes #23958). Discussion ---------- [Lock] Fix race condition in tests between cache and lock component | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | Currently trying to fix * [x] php 5.5 in testSaveWithDifferentResources "Failed asserting that false is true" * [x] php 5.5 in testSaveWithDifferentKeysOnSameResources "The store shouldn't save the second key" Workflow: * [x] find a reproducer * [x] fix memcached tests => #23969 * [x] fix redis tests => this PR Commits ------- 26948cf Fix race condition in tests between cache and lock
Uh oh!
There was an error while loading. Please reload this page.