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

fix: cache #3804

Merged
merged 17 commits into from
Nov 6, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
WIP
  • Loading branch information
ronag committed Nov 6, 2024
commit 74c159905102cfde883e1fe8bc887f743e12d100
23 changes: 7 additions & 16 deletions lib/interceptor/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,24 +124,15 @@ module.exports = (opts = {}) => {
// Check if the response is stale
const now = Date.now()
if (now >= value.staleAt) {
// TODO (fix): This whole bit is a bit suspect. In particular given that
// we dumped the body above.

if (now >= value.deleteAt) {
// Safety check in case the store gave us a response that should've been
// deleted already
return dispatch(opts, new CacheHandler(globalOpts, opts, handler))
}

if (!opts.headers) {
opts.headers = {}
}

opts.headers['if-modified-since'] = new Date(value.cachedAt).toUTCString()

// Need to revalidate the response
return dispatch(
opts,
{
...opts,
headers: {
...opts.headers,
'if-modified-since': new Date(value.cachedAt).toUTCString()
}
},
new CacheRevalidationHandler(
() => respondWithCachedValue(stream, value),
new CacheHandler(globalOpts, opts, handler)
Expand Down
Loading