Skip to content

User cache purge #3189

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

Merged
merged 6 commits into from
Mar 12, 2018
Merged

User cache purge #3189

merged 6 commits into from
Mar 12, 2018

Conversation

di
Copy link
Member

@di di commented Mar 8, 2018

Fixes #2861.

This PR enables purging pages related to the User model whenever either the User model changes, or any projects/releases related to that user.

To do so, we need to be able to generate cache keys from some iterable attribute on the changed object (like Project.users or Release.project.users).

@di di requested a review from dstufft March 8, 2018 23:36
@di di force-pushed the user-cache-purge branch from d24f7f8 to 8b17aae Compare March 8, 2018 23:37
purge_keys=["project/{obj.normalized_name}", "all-projects"],
cache_keys=[
key_factory("project/{obj.normalized_name}"),
key_factory("user/{itr.username}", iterate_on='users'),
Copy link
Member

Choose a reason for hiding this comment

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

What changes to a user would get reflected on pages that use the Project model?

Copy link
Member Author

Choose a reason for hiding this comment

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

Technically if the user changes their primary email, their avatar would change, which is shown on the "Maintainers" section for project/release pages.

Also if we ever ship #1190, the URLs to maintainers would be wrong.

Copy link
Member

Choose a reason for hiding this comment

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

My primary concern is that there is a limit to how many surrogate keys (what these are) we can attach to a single HTTP response. Since we have no control over how many users can get added to a single project, that would mean that a page may have more surrogate keys than we can support in a single response (and I believe what happens then is that we just silently lose some of the surrogate keys).

I think probably it doesn't make sense to support iterate_on for cache keys because we can't control how many keys are going to get added. However iterate_on for purge keys makes total sense, and this example here could easily be implemented by, instead of adding a cache key for user to each page, adding a purge key to User that is something like key_factory("project/{itr.normalized_name}", iterate_on="projects"). That should have the same effect, without the unbounded surrogate key problem.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, and if you make that change, add a comment please about why one supports it and one doesn't, otherwise it'll probably be an attractive nuisance for people wanting to add support for it to cache keys and relying on tribal knowledge for why.

purge_keys=["project/{obj.project.normalized_name}", "all-projects"],
cache_keys=[
key_factory("project/{obj.project.normalized_name}"),
key_factory("user/{itr.username}", iterate_on='project.users'),
Copy link
Member

Choose a reason for hiding this comment

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

Same question as above, what change to a user requires invalidating the cache for anything that uses the Release model?

di added 5 commits March 9, 2018 12:37
This also makes it impossible to use the `key_factory` and `iterate_on`
with cache keys, to avoid the problem of unbounded surrogate keys.
We don't need to do this per-project to purge the cache anymore.
@di di force-pushed the user-cache-purge branch from 8b17aae to 2bcc0a4 Compare March 9, 2018 23:50
@di
Copy link
Member Author

di commented Mar 10, 2018

@dstufft This is ready for re-review.

@di di merged commit b378e8e into pypi:master Mar 12, 2018
@di di deleted the user-cache-purge branch March 12, 2018 17:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants