Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
fabpot merged 1 commit intosymfony:3.3fromnicolas-grekas:cache-version
Aug 31, 2017

Conversation

@nicolas-grekas
Copy link
Member

@nicolas-grekasnicolas-grekas commentedAug 24, 2017
edited
Loading

QA
Branch?3.3
Bug fix?yes
New feature?no
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets#23960
LicenseMIT
Doc PR-

@nicolas-grekasnicolas-grekas added this to the3.3 milestoneAug 24, 2017
@nicolas-grekasnicolas-grekas changed the title[Cache] Use namespace versioning for backends that dont support clear…[Cache] Use namespace versioning for backends that dont support clearing by keysAug 24, 2017
@nicolas-grekasnicolas-grekasforce-pushed thecache-version branch 3 times, most recently fromd33fc54 toc15d72eCompareAugust 24, 2017 06:55
{
CacheItem::validateKey($key);

if ($this->versioningIsEnabled &&'' ===$this->namespaceVersion) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Other classes used the trickisset($string[0]) to check if their is a namespace.

Copy link
MemberAuthor

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

@nicolas-grekas
Copy link
MemberAuthor

with new false positive from php-cs-fixer...

Copy link

@hcomnetworkershcomnetworkers left a 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.)

@nicolas-grekas
Copy link
MemberAuthor

nicolas-grekas commentedAug 24, 2017
edited
Loading

put a colon after the namespace while colons are not allowed in validateKey

I put a colonbecause they are not allowedwhen given from the outside. Here, we'repast 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.

why an integer is not allowed as cache key

because PSR-6/16 states that a key must be a string. So6 is not allowed, but"6" is.

@andrerom
Copy link

andrerom commentedAug 26, 2017
edited
Loading

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

@nicolas-grekas
Copy link
MemberAuthor

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?

@andrerom
Copy link

andrerom commentedAug 26, 2017
edited
Loading

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 :)

@nicolas-grekas
Copy link
MemberAuthor

nicolas-grekas commentedAug 27, 2017
edited
Loading

there will be bug report for this down the line for long running processes

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:
$pool->enableVersioning() || $pool->enableVersioning(false);

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.

@jderusse
Copy link
Member

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.
(I'm not sur it exists and it'd a good idea.. just a brainstorm idea of what could be wrong)

@andrerom
Copy link

andrerom commentedAug 27, 2017
edited
Loading

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.

@nicolas-grekas
Copy link
MemberAuthor

to clearly document handlers/ connection classes that don't support flushing

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$pool->enableVersioning() on pools that have versioning enabled.
(or call$pool->enableVersioning() || $pool->enableVersioning(false), which works whether versioning is on or not, without changing the versioning-enabled state.)

@fabpot
Copy link
Member

Thank you@nicolas-grekas.

@fabpotfabpot merged commitf8a7518 intosymfony:3.3Aug 31, 2017
fabpot added a commit that referenced this pull requestAug 31, 2017
…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
@nicolas-grekasnicolas-grekas deleted the cache-version branchSeptember 1, 2017 06:57
*
* 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.
*
Copy link
Contributor

@robfrawleyrobfrawleySep 1, 2017
edited
Loading

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"

Copy link
Member

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?

nicolas-grekas reacted with thumbs up emoji
Copy link
Contributor

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

Copy link
MemberAuthor

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 :)

robfrawley reacted with heart emoji
nicolas-grekas added a commit that referenced this pull requestSep 3, 2017
…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 PRCommits-------26948cf Fix race condition in tests between cache and lock
@fabpotfabpot mentioned this pull requestSep 11, 2017
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@javiereguiluzjaviereguiluzjaviereguiluz left review comments

@jderussejderussejderusse left review comments

@fabpotfabpotfabpot approved these changes

+2 more reviewers

@robfrawleyrobfrawleyrobfrawley left review comments

@hcomnetworkershcomnetworkershcomnetworkers approved these changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

3.3

Development

Successfully merging this pull request may close these issues.

8 participants

@nicolas-grekas@andrerom@jderusse@fabpot@javiereguiluz@robfrawley@hcomnetworkers@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp