Commit 992c6d8
fix: implement proper stale-while-revalidate behavior per RFC 5861 (#4492)
* fix: implement proper stale-while-revalidate behavior per RFC 5861
The stale-while-revalidate cache directive was not working as intended.
Instead of returning stale content immediately and revalidating in the
background, it was performing synchronous revalidation, defeating the
primary purpose of reducing latency.
This fix:
- Returns stale content immediately when within the stale-while-revalidate window
- Performs background revalidation asynchronously to update the cache
- Updates tests to reflect the correct RFC 5861 behavior
Fixes #4471
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: Matteo Collina <hello@matteocollina.com>
* test: use timers/promises for sleep instead of creating promises
Replace manual Promise creation with setTimeout from timers/promises
for cleaner and more idiomatic async delays in tests.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: Matteo Collina <hello@matteocollina.com>
* fix: use process.nextTick instead of setImmediate for background revalidation
setImmediate doesn't work properly with fake timers in tests, causing
background revalidation to not trigger. process.nextTick works correctly
with both real time and fake timers.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: Matteo Collina <hello@matteocollina.com>
* Update cache.js
Co-authored-by: Aras Abbasi <aras.abbasi@googlemail.com>
---------
Signed-off-by: Matteo Collina <hello@matteocollina.com>
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Aras Abbasi <aras.abbasi@googlemail.com>1 parent d79870d commit 992c6d8
2 files changed
Lines changed: 274 additions & 22 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
59 | 75 | | |
60 | 76 | | |
61 | 77 | | |
| |||
231 | 247 | | |
232 | 248 | | |
233 | 249 | | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
234 | 295 | | |
235 | 296 | | |
236 | 297 | | |
| |||
0 commit comments