Skip to content

Conversation

@lognaturel
Copy link
Member

@lognaturel lognaturel commented May 12, 2025

Closes #1048

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

Put it on the dev server. Verified that there's exactly one Cache-Control header and that it's set as expected.

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

We could also set the headers here to private, no-cache, etc. But then we'd be setting duplicate headers which could drift between nginx and backend. I think it's clearer to make caching headers clearly the backend's responsibility.

Note that this does not set the Pragma header for backend. I think we could do away with it altogether because it has been deprecated for a long time.

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?

Backend responses should be cached in private caches. We should get 304s.

Does this change require updates to documentation? If so, please file an issue here and include the link below.

No.

Before submitting this PR, please make sure you have:

  • branched off and targeted the next branch OR only changed documentation/infrastructure (master is stable and used in production)
  • verified that any code or assets from external sources are properly credited in comments or that everything is internally sourced

@lognaturel lognaturel requested a review from sadiqkhoja May 12, 2025 23:58
@lognaturel lognaturel marked this pull request as ready for review May 12, 2025 23:58
map $cache_strategy $cache_header_cache_control {
"immutable" "max-age=31536000";
"revalidate" "no-cache";
"passthrough" "";
Copy link
Member Author

Choose a reason for hiding this comment

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

I verified that if there's no value set for a header, that header isn't set by nginx.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see a PR to update nginx docs: "The add_header directive will not generate a header if the value provided is an empty string." except if it is multi-value header

nginx/nginx.org#51

default "single-use";
}
map $cache_strategy $cache_header_cache_control {
"immutable" "max-age=31536000";
Copy link
Member Author

Choose a reason for hiding this comment

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

I think this should be public, max-age=31536000, immutable otherwise we don't know if intermediary caches will cache.

Copy link
Contributor

Choose a reason for hiding this comment

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

makes sense

}
map $cache_strategy $cache_header_cache_control {
"immutable" "max-age=31536000";
"revalidate" "no-cache";
Copy link
Member Author

Choose a reason for hiding this comment

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

Same as above, I think we can/should add public.

@matthew-white matthew-white linked an issue May 13, 2025 that may be closed by this pull request
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 to me. However, we should add one or two tests in test-nginx.js

default "single-use";
}
map $cache_strategy $cache_header_cache_control {
"immutable" "max-age=31536000";
Copy link
Contributor

Choose a reason for hiding this comment

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

makes sense

@lognaturel lognaturel merged commit a4c945f into next May 13, 2025
10 checks passed
@lognaturel
Copy link
Member Author

@sadiqkhoja please verify the tests and either open a PR to fix or send me some comments if they're not right/complete!

@lognaturel lognaturel deleted the backend-cache-headers branch May 13, 2025 04:38
sadiqkhoja added a commit to sadiqkhoja/central that referenced this pull request May 13, 2025
* Update assertions: Header object doesn't have headers as properties, we have to use .has()
* Update mock-http-server to return cache headers for a sample API
* Add test to assert that backend cache headers are passed through
sadiqkhoja added a commit to sadiqkhoja/central that referenced this pull request May 13, 2025
* Update assertions: Header object doesn't have headers as properties, we have to use .has()
* Update mock-http-server to return cache headers for a sample API
* Add test to assert that backend cache headers are passed through
sadiqkhoja added a commit that referenced this pull request May 13, 2025
* Update assertions: Header object doesn't have headers as properties, we have to use .has()
* Update mock-http-server to return cache headers for a sample API
* Add test to assert that backend cache headers are passed through
yanokwa pushed a commit to yanokwa/odk-central that referenced this pull request Jun 11, 2025
yanokwa pushed a commit to yanokwa/odk-central that referenced this pull request Jun 11, 2025
* Update assertions: Header object doesn't have headers as properties, we have to use .has()
* Update mock-http-server to return cache headers for a sample API
* Add test to assert that backend cache headers are passed through
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.

List of Projects on Main page takes much longer to load

3 participants