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

Add cache headers to responses #1454

Open
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

alxndrsn
Copy link
Contributor

@alxndrsn alxndrsn commented Mar 18, 2025

Resubmission of #1390


Closes getodk/central#662

What has been done to verify that this works as intended?

Added tests.

Why is this the best possible solution? Were any other approaches considered?

It seems simple.

An alternative approach was tried in #1390, but it was decided that content should be cached for less time.

This PR also adds more extensive tests which were not present in #1390.

Previously, max-age=0 was being used, to ensure that any cached values were immediately considered stale. This has been changed to no-cache, which allows caching but requires revalidation on every use. See:

How does this change affect users? Describe intentional changes to behavior and behavior that could have accidentally been affected by code changes. In other words, what are the regression risks?

Should prevent future caching surprises.

Does this change require updates to the API documentation? If so, please update docs/api.yaml as part of this PR.

No? "cache" is not currently mentioned in docs/

Before submitting this PR, please make sure you have:

  • run make test and confirmed all checks still pass OR confirm CircleCI build passes
  • verified that any code from external sources are properly credited in comments or that everything is internally sourced

@alxndrsn alxndrsn marked this pull request as ready for review March 18, 2025 13:58
[
() => `${serverUrl}/v1/projects/${projectId}`,
() => `${serverUrl}/v1/projects/${projectId}/forms/${encodeURIComponent(xmlFormId)}`,
() => `${serverUrl}/v1/projects/${projectId}/forms/${encodeURIComponent(xmlFormId)}.svc/Submissions('cache-test-submission')`,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This could be reduced to testing a single URL.

@alxndrsn alxndrsn requested a review from sadiqkhoja April 1, 2025 11:48
Copy link
Contributor

@sadiqkhoja sadiqkhoja left a comment

Choose a reason for hiding this comment

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

Looks good

@alxndrsn
Copy link
Contributor Author

alxndrsn commented Apr 2, 2025

@lognaturel I think there's an argument for setting Cache-Control: no-store on all API responses: this PR's current default of Cache-Control: private, no-cache will allow storage of responses in browsers' local cache. For single-user devices this is probably not an issue, but for shared devices this potentially means that central response content and headers will be stored on disk.

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.

Cloudflare caches Entity Lists for longer than expected
2 participants