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] Add hierarchical invalidation with ContextAwareAdapterInterface#19521

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

Closed

Conversation

@nicolas-grekas
Copy link
Member

@nicolas-grekasnicolas-grekas commentedAug 3, 2016
edited
Loading

QA
Branch?master
Bug fix?no
New feature?yes
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets-
LicenseMIT
Doc PRsymfony/symfony-docs#6858

This PR adds a public interface to do hierachical invalidation. By using the newwithContext() method, one is able to create a contextualized set of cache keys. Invalidating is as easy as changing the context identifier provided as argument.
Contexts can be chained to create subcontexts inside contexts.
All subcontexts share the same adapter implementation + connection state.
Clearing a parent clears all subcontexts.

This feature is already implemented by e.g. Drupal 8, and it plays nice with tags: all forks share the same tags space.

@nicolas-grekas
Copy link
MemberAuthor

For reference, the intent of this PR is to provide a basic block that could allow building something like Drupal Contexts:
https://www.drupal.org/developing/api/8/cache/contexts

return$this->namespace.$key;
}
if (strlen($id =$this->namespace.$key) >$this->maxIdLength) {
$id =$this->namespace.substr(str_replace('/','-',base64_encode(md5($key,true))),0, -2);
Copy link
MemberAuthor

@nicolas-grekasnicolas-grekasAug 5, 2016
edited
Loading

Choose a reason for hiding this comment

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

Namespace prefix excluded, this produces a string of length 22 (thus the 22/23 in the code)
(the last two cut chars are padding=)

@nicolas-grekasnicolas-grekasforce-pushed thecache-fork branch 6 times, most recently from4e02558 toec4957bCompareAugust 7, 2016 15:07
nicolas-grekas added a commit that referenced this pull requestAug 7, 2016
…s-grekas)This PR was merged into the 3.1 branch.Discussion----------[Cache] Use SCAN instead of KEYS with Redis >= 2.8| Q             | A| ------------- | ---| Branch?       | 3.1| Bug fix?      | yes| New feature?  | no| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets | -| License       | MIT| Doc PR        | -With#19521 coming,  clearing cache keys by prefix is going to be used a lot more often.Time to fix Redis cache clearing.Commits-------aadeb11 [Cache] Use SCAN instead of KEYS with Redis >= 2.8
@nicolas-grekasnicolas-grekasforce-pushed thecache-fork branch 3 times, most recently from5fa8d1f to024ea79CompareAugust 7, 2016 16:33
@nicolas-grekas
Copy link
MemberAuthor

@andrerom or anyone else, any comment here?

@andrerom
Copy link

So this can for instance be used by HttpCache so it can handle very by logic right?

@nicolas-grekas
Copy link
MemberAuthor

nicolas-grekas commentedSep 2, 2016
edited
Loading

Yes for sure.https://www.drupal.org/developing/api/8/cache/contexts is a real use case of this feat. Maybe one should first read this page then help me find the right words to explain the feat. ? :)
This is hierarchical invalidation done from theoutside, (theinside being prefixing keys explicitly e.g.->getItem('foo/bar'))

@andrerom
Copy link

well I looked at that page, and couldn't help but think most of these use cases(incl Http Cache) could be solved by reflecting context in key, as invalidation is done with tags it won't complicate invalidation, and lookup will need to know the context of what they are looking for anyway.

But I'm probably overlooking something.

@nicolas-grekas
Copy link
MemberAuthor

nicolas-grekas commentedSep 2, 2016
edited
Loading

could be solved by reflecting context in key

true, and this feat. is exactly here for decoupling this: context computation and keys.
You can create the context outside, then give a regular but contextualized adapter to another service that shouldn't care about the context it's working in.

@nicolas-grekasnicolas-grekas changed the title[Cache] Add namespace based invalidation with ForkableAdapterInterface[Cache] Add hierarchical invalidation with ContextAwareAdapterInterfaceSep 14, 2016
@nicolas-grekas
Copy link
MemberAuthor

nicolas-grekas commentedSep 14, 2016
edited
Loading

Vocabulary changed: the interface is now calledContextAwareAdapterInterface and its methodwithContext().

@nicolas-grekas
Copy link
MemberAuthor

Any comment here? Any vote @symfony/deciders?

@nicolas-grekas
Copy link
MemberAuthor

So, thinking a bit more about this: should calling deleteItem on a parent also clear the item recursively? Looks like it could be useful. Then what about the other psr6 methods? Dunno. Which means this isn't ready :)
Closing

@nicolas-grekasnicolas-grekas deleted the cache-fork branchSeptember 23, 2016 18:51
fabpot added a commit that referenced this pull requestSep 24, 2016
…ant using hashing (nicolas-grekas)This PR was merged into the 3.2-dev branch.Discussion----------[Cache] Handle arbitrary key length when the backend cant using hashing| Q             | A| ------------- | ---| Branch?       | master| Bug fix?      | no| New feature?  | yes| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets | -| License       | MIT| Doc PR        | -Saving some bits from#19521 :) Already awaited by PdoAdapter which defines the property.Commits-------11f448f [Cache] Handle arbitrary key length when the backend cant using hashing
@LionsAd
Copy link

The reason why there was confusion is that you need a 2-step cache_get() process - or a cache collector like 'Vary' if you want to use that.

It gets very useful once you have a sub-item use contexts that are not known to the parent.

It basically solves the problem for complex sub-items, which the parent can't query for its contexts and which even might not know its contexts until computation time.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

4 participants

@nicolas-grekas@andrerom@LionsAd@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp