Set cache control header on API responses #4005
Labels
💻 aspect: code
Concerns the software code in the repository
🧰 goal: internal improvement
Improvement that benefits maintainers, not users
🟧 priority: high
Stalls work on the project or its dependents
🧱 stack: api
Related to the Django API
💬 talk: discussion
Open for discussions and feedback
Problem
We do not set cache-control headers on our API responses at the origin, and instead rely on Cloudflare to set these.
While we can continue configuring specific cache-control settings, Cloudflare is able to interpret cache control headers from upstream responses and use those settings for edge TTL. That would simplify our Cloudflare configuration by removing the details of individual endpoints and allow that to live instead in the API code, where it probably belongs.
This wouldn't preclude us adding additional cache settings in Cloudflare if we ever wanted to.
Description
Add the
cache_control
decorator to the API views, with TTL as listed. The TTLs are taken from our Cloudflare configuration and for this issue we'll take for granted that they are correct, and defer modifications to these TTLs to a future issue if needed.Lastly, explicitly exclude the
auth_tokens
routes by addingnever_cache
. This again reduces configuration necessary in Cloudflare and moves it upstream into our code.Additional context
This is a supplement to https://github.com/WordPress/openverse-infrastructure/issues/777, removing the need to move many of the rules defined in our Cloudflare configuration to the the openverse.org zone. As such, I'm setting it to high priority and into the todo list and starting work on it ASAP as part of the openverse.org migration project. This doesn't block that issue because, as I've written in the issue, we'll just ignore the .engineering caching rules and add a single rule to instruct Cloudflare to use the upstream header.
The text was updated successfully, but these errors were encountered: