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

cache: fix stale-while-revalidate and stale-if-error #3865

Merged
merged 4 commits into from
Nov 25, 2024

Conversation

flakey5
Copy link
Member

@flakey5 flakey5 commented Nov 22, 2024

Closes #3853

This cleans up the cache interceptor file. This also makes the cache stores store the responses' cache control directives. This was the nicest way I could think of to implement stale-if-error and also sets it up nicely for if we ever allow for more cache control directive extensions.

lib/interceptor/cache.js Outdated Show resolved Hide resolved
@metcoder95
Copy link
Member

types seems to be failing

@ronag
Copy link
Member

ronag commented Nov 23, 2024

@flakey5 can you rebase?

*/
constructor (callback, handler) {
constructor (callback, handler, allowErrorStatusCodes) {
Copy link
Member

Choose a reason for hiding this comment

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

Why is this necessary?

Copy link
Member Author

Choose a reason for hiding this comment

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

For stale-if-error, error status codes when revalidating mean to use the stale response

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

There are plenty of merge errors

lib/handler/cache-revalidation-handler.js Outdated Show resolved Hide resolved
lib/handler/cache-revalidation-handler.js Outdated Show resolved Hide resolved
Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

lgtm

test/types/cache-interceptor.test-d.ts Outdated Show resolved Hide resolved
test/interceptors/cache.js Outdated Show resolved Hide resolved
Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

lgtm

@mcollina mcollina merged commit 71b6b0b into nodejs:main Nov 25, 2024
37 checks passed
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.

cache: Implement stale-while-revalidate and stale-if-error
4 participants