Repository navigation
Cache only 200 SSR responses, not the 200-209 range - #6360
Conversation
74f2d11 to
67f41f5
Compare
67f41f5 to
140e56a
Compare
|
@Kasinhou : Thanks for this contribution. However, it looks (to me) like this overlaps with changes already suggested in #6352 by @saschaszott ...except this PR makes different changes. I think we'll need some more discussion between these two PR to determine which approach seems better for DSpace. It looks like there's disagreement over whether to cache all 2xx responses, or just specifically 200. (Personally, I can see both arguments...so I'd like to gather feedback from others here.) |
|
@tdonohue @saschaszott I would argue that, specifically for the SSR page cache, this is straightforward: only HTTP 200 (GET) responses should be eligible for caching. This is not a general statement about HTTP caching. Caching redirects (301, 308) or negative responses (404, 410) can make sense, but that is best handled as a separate concern with dedicated TTLs. The purpose of the SSR cache is to store successfully rendered HTML pages using GET, rather than broader HTTP success states. For example:
These do not seem to provide a useful reason to cache the response as a complete SSR-generated HTML page. As far as I know, DSpace SSR does not currently produce these statuses. But accepting the entire 2xx range does not seem to add any practical benefit, while potentially allowing unexpected caching behaviour in the future. To be precise, HTTP 200 is a necessary, but not sufficient, condition for caching a successfully rendered page. A rendering failure could still produce HTTP 200 with an error message in the HTML, but that is a separate issue. For this particular cache, feels like the safest and cleanest baseline to accept only 200. This applies also to #6352 |
|
@vidiecan , @tdonohue : I hadn't really considered the existing regex (btw: it checks for 20X instead of 2XX). I just wanted to replace it with a simpler range comparison. If you think we should only check for an exact 200 response code, then we should go with that. However, perhaps @atarix83 could also provide some feedback on this regex check? He originally added it in this commit: 6a58e49 |
tdonohue
left a comment
There was a problem hiding this comment.
👍 Thanks @Kasinhou and @vidiecan ! After reviewing @vidiecan 's notes again, and testing this PR myself, I think this is a better approach than the current code. I agree that other this is sufficient because SSR is not going to return these other 2xx response codes, and even if it did, there's nothing useful to "cache" (i.e. often no response body).
I've also verified that this change doesn't reintroduce #2333 (which is the ticket fixed by the code which added this check against 2xx response codes).
So, this small change looks good to me. I'm going to merge it immediately and attempt to auto-backport it to our maintenance branches.
|
Successfully created backport PR for |
|
Successfully created backport PR for |
|
Successfully created backport PR for |
Description
Replace the
/^20+/regex guard (allowing also 201-209) withstatusCode === 200check. SSR only caches 200 renders.No regression, the only difference is that 201-209 responses are no longer cached.
AI Disclosure (REQUIRED)
Were AI tools used in the creation of this PR?
AI (Claude Opus 4.8) helped me investigate where saving to cache is called and when saving is skipped, and to
suggest the change. I reviewed and modified the code. The change is only a one-line guard in server.ts.
Checklist
This checklist provides a reminder of what we are going to look for when reviewing your PR. You do not need to complete this checklist prior creating your PR (draft PRs are always welcome).
However, reviewers may request that you complete any actions in this list if you have not done so. If you are unsure about an item in the checklist, don't hesitate to ask. We're here to help!
mainbranch of code (unless it is a backport or is fixing an issue specific to an older branch).npm run lintnpm run check-circ-deps)package.json), I've made sure their licenses align with the DSpace BSD License based on the Licensing of Contributions documentation.