Skip to content

Proxito: simplify caching logic #10067

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 3 commits into from
Mar 1, 2023
Merged

Proxito: simplify caching logic #10067

merged 3 commits into from
Mar 1, 2023

Conversation

stsewd
Copy link
Member

@stsewd stsewd commented Feb 23, 2023

Instead of relying on our Cloudflare's rules, we are defining explicitly what not to cache in our code.
I like that we are explicitly asking to cache or not things in our code, but I don't like that we depend on the ALLOW_PRIVATE_REPOS setting, but that's better to cache all types of responses on .org.

After deploying this, we can remove several of our CF rules.

Closes #10031

@stsewd stsewd force-pushed the simplify-caching-logic branch from 3f7024c to 9300676 Compare February 23, 2023 21:32
Caching is enabled for all projects now.
We always check for the privacy level to explicitly cache or
not a response, if the response isn't explicitly cached or not,
we use the default, this default depends if we are on .org or .com
(we cache everything on .org, and on .com we cache responses attached to
public versions).

Closes #10031
@stsewd stsewd force-pushed the simplify-caching-logic branch from 9300676 to 119500c Compare February 27, 2023 18:10
@stsewd stsewd marked this pull request as ready for review February 27, 2023 18:21
@stsewd stsewd requested a review from a team as a code owner February 27, 2023 18:21
@stsewd stsewd requested a review from benjaoming February 27, 2023 18:21
@ericholscher
Copy link
Member

ericholscher commented Feb 27, 2023

@stsewd Love these PR comments, and seems like we're doing a good job of also adding code comments. They're useful on deleted code generally, and I really appreciate the context you share, and it gets lost if it doesn't live with the code! This PR is great, so 💯

Copy link
Member

@ericholscher ericholscher left a comment

Choose a reason for hiding this comment

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

Excited for this! I had a couple larger ideas for additional features in my comments, but I don't want to block this PR on additional ideas. I'm fine getting this cleaned up and merged, with additional features done in future PR's. I'm really liking this small approach to PR's you're doing, so don't let me feature creep it :)


Views that can be cached should always return the same response for all
users (anonymous and authenticated users), like when the version attached
to the request is public.

To cache a view you can either set the `cache_request` attribute to `True`,
To explicitly cache a view you can either set the `cache_response` attribute to `True`/`False`,
or override the `can_be_cached` method.
Copy link
Member

Choose a reason for hiding this comment

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

Which takes precedence? We should likely document the order we check things, so it's clear how the logic is interpreted.

Copy link
Member

Choose a reason for hiding this comment

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

Why do we have two different ways of doing the same? Can we have just one? 😄

HTTP_HOST="project.dev.readthedocs.io",
)
self.assertEqual(resp.status_code, 200)
extension = "zip" if type_ == MEDIA_TYPE_HTMLZIP else type_
Copy link
Member

Choose a reason for hiding this comment

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

This seems like a code smell... Probably should have named htmlzip as zip... 🙃

Copy link
Member

@humitos humitos left a comment

Choose a reason for hiding this comment

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

It looks really good to me. I think there are some comments and suggestions to be addressed and we can merge and deploy after that.


Views that can be cached should always return the same response for all
users (anonymous and authenticated users), like when the version attached
to the request is public.

To cache a view you can either set the `cache_request` attribute to `True`,
To explicitly cache a view you can either set the `cache_response` attribute to `True`/`False`,
or override the `can_be_cached` method.
Copy link
Member

Choose a reason for hiding this comment

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

Why do we have two different ways of doing the same? Can we have just one? 😄

Comment on lines +546 to +547
# Always cache this view, since it's the same for all users.
cache_response = True
Copy link
Member

Choose a reason for hiding this comment

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

It was a little confusing to me that we are sometimes using this variable as a class-variable and some other times we are declaring/changing inside a method, making it an instance-variable.

I think this is fine, but we could expand the original comment in the CDN mixin explaining this in a better way.

@ericholscher ericholscher linked an issue Feb 28, 2023 that may be closed by this pull request
@stsewd stsewd force-pushed the simplify-caching-logic branch from caa1245 to 00a84b1 Compare February 28, 2023 21:51
Copy link
Member

@ericholscher ericholscher left a comment

Choose a reason for hiding this comment

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

I think this looks good to me. 👍

Should we be adding any validatehttp checks for high-value cache behavior?

To explicitly cache a view you can either set the `cache_response`
attribute to `True`/`False`, or override the `can_be_cached` method
(which defaults to return the `cache_response` attribute).
If set to `None` (default), the cache header won't be set, so the default
Copy link
Member

Choose a reason for hiding this comment

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

💯

@stsewd
Copy link
Member Author

stsewd commented Mar 1, 2023

Should we be adding any validatehttp checks for high-value cache behavior?

Adding!

@stsewd stsewd merged commit 9d07164 into main Mar 1, 2023
@stsewd stsewd deleted the simplify-caching-logic branch March 1, 2023 16:47
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.

Simplify caching logic Proxito: Next steps on Improve URL Handling
3 participants