Skip to content
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

Make http error cache control behavior configurable. #444

Merged
merged 2 commits into from
Mar 3, 2022

Conversation

sharkinsspatial
Copy link
Member

What I am changing

While implementing edge caching for a titiler deployment we have a case where underlying source COGs are continually added in real time. Currently a request that results in 404 No assets found for tile has the same Cache-Control header as a 200 response and is maintained by the edge cache for the same duration. In our case we would prefer 404 responses to have a shorter duration in the edge cache so that requests are passed to the origin (where new assets may now be available). This PR makes the upper range or http codes which include a Cache-Control header configurable so that edge caches can exert finer control on error response cache duration.

How I did it

Extended core/middleware to support a configurable upper bound for response codes which include a Cache-Control header rather than the hardcoded 500 value.

How you can test it

Via the project's tox testing entrypoint.

@@ -31,6 +32,7 @@ def __init__(
"""
super().__init__(app)
self.cachecontrol = cachecontrol
self.cachecontrol_http_code_range = cachecontrol_http_code_range
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure about the name of the parameter. To me if we say Range I'm assuming the input to be a sequence (min, max), while here in reality we want the upper value of status_code.

what do you think about cachecontrol_max_http_code ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Strong agree 👍 .

@vincentsarago vincentsarago self-requested a review March 3, 2022 18:57
Copy link
Member

@vincentsarago vincentsarago left a comment

Choose a reason for hiding this comment

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

🙏 thanks @sharkinsspatial

@vincentsarago vincentsarago merged commit 7b8d4d9 into master Mar 3, 2022
@vincentsarago vincentsarago deleted the configure_cache_control branch March 3, 2022 18:58
@sharkinsspatial
Copy link
Member Author

I may revisit this a bit later @vincentsarago I'm still not fully sure of the Cloudfront behavior between Cache-Control and Max TTL for error responses but this should help diagnose. 🙇

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