-
Notifications
You must be signed in to change notification settings - Fork 530
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
feat: http caching #3562
base: main
Are you sure you want to change the base?
feat: http caching #3562
Conversation
Would it maybe be better to use jsdoc types rather than separate type definition files? @mcollina |
I think using type definitions are in line with the rest of the codebase, and therefore the correct implementation. If we want to migrate to a jsdoc-generated world, let's discuss in another issue! |
e07e3ec
to
938fa7a
Compare
Implements bare-bones http caching as per rfc9111 Closes nodejs#3231 Closes nodejs#2760 Closes nodejs#2256 Closes nodejs#1146 Co-authored-by: Carlos Fuentes <[email protected]> Co-authored-by: Robert Nagy <[email protected]> Co-authored-by: Isak Törnros <[email protected]> Signed-off-by: flakey5 <[email protected]>
938fa7a
to
f69a8b2
Compare
Signed-off-by: flakey5 <[email protected]>
Signed-off-by: flakey5 <[email protected]>
Signed-off-by: flakey5 <[email protected]>
Co-authored-by: Robert Nagy <[email protected]>
Co-authored-by: Carlos Fuentes <[email protected]>
Signed-off-by: flakey5 <[email protected]>
Signed-off-by: flakey5 <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
headers could be null or undefined
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ronag
Should we use fastTimers?
Co-authored-by: Robert Nagy <[email protected]>
Hmm so with sharing an in-flight response to requests to the same resource, how do we want to handle if the body ends up exceeding the Currently when this happens, we close the writable. However, the readables waiting for body chunks are just left hanging. I think we could either
The first would be the easiest to implement but the second is what I intuitively think would happen. The second option comes with some implementation difficulties though. When we create the read stream in the interceptor, we would need to listen for some The implementation would look something like const dataChunks = []
stream.on('data', dataChunks.push)
let passedToOrigin = false
stream.on('passToOrigin', () => {
passedToOrigin = true
dispatch(opts, handler)
})
stream.on('end', () => {
if (!passedToOrigin) {
// actually send the body chunks
}
}) Adding to it, this doesn't apply to HEAD requests since there isn't a response body for those. Something that might work is allowing stream.on('end', chunks => {/* ... */})
stream.on('passedToOrigin', () => {/* dispatch */}) If we want to, we could go with option 1 for simplicity sakes and then later down the road add support for option 2. Wdyt? |
Signed-off-by: flakey5 <[email protected]>
Signed-off-by: flakey5 <[email protected]>
Signed-off-by: flakey5 <[email protected]>
TBH I think we should skip in-flight de-duplication in this first phase. @mcollina wdyt? I would propose: Step 1: in-memory cache |
I think this might be handled here already. Why do you want to remove it? |
|
Signed-off-by: flakey5 <[email protected]>
To add to this, I'll also be opening another pr that adds support for cache control directives specified by the request (wip branch https://github.com/flakey5/undici/tree/flakey5/20240924/cli-cache-control) |
Signed-off-by: flakey5 <[email protected]>
Signed-off-by: flakey5 <[email protected]>
Pushed a commit removing the request de-dupe code re #3562 (comment) and #3562 (comment). Can revert it if we do want to have it, but, I agree that it should be added afterwards in a pr dedicated to it. That way we can address the issues there without tying the rest of this up. |
Signed-off-by: flakey5 <[email protected]>
Co-authored-by: Matteo Collina <[email protected]>
Signed-off-by: flakey5 <[email protected]>
Signed-off-by: flakey5 <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have opinions... Will try to make time over weeekend.
Signed-off-by: flakey5 <[email protected]>
Implements bare-bones opt-in http caching as per rfc9111. Bare-bones in this case means what's required by the spec and a few extra bits, with more coming in future prs.
Opening as a draft since there's still some more work to be done (mostly tests, but a bit more functionality-wise)No request cache directives are supported at this time, this will come later.
Response caching directives supported:
public
private
s-maxage
max-age
Expires
headerno-cache
no-store
stale-while-revalidate
This relates to...
Closes #3231
Closes #2760
Closes #2256
Closes #1146
Changes
Features
Bug Fixes
n/a
Breaking Changes and Deprecations
n/a
Status