Commit 9cbc65a
committed
fix(memoization): refresh timestamp on resolve, bump LRU on stale-dedup
`memoizeAsync` set `entry.timestamp` when a cache miss STARTED its
`fn(...)` call. For a fn that takes longer than ttl — say ttl=200ms,
fn=500ms — the value landed already classified as expired: `Date.now()
- entry.timestamp` would be ~500 > ttl at the moment the resolve
handler installed `entry.value`. Subsequent calls hit the "expired but
refreshing?" branch, found `refreshing` emptied by the same resolve
handler, fell through to cache-delete + fresh `fn()`. Every caller past
the first ttl window re-fetched, defeating the cache.
Also plugs a recency gap: the stale-dedup branch awaited the in-flight
refresh but did not bump `accessOrder`, so an entry mid-refresh could
be evicted by LRU pressure even while a peer was computing a fresh
value on its behalf.
Regression test uses vi.useFakeTimers with fn=500ms, ttl=200ms; asserts
the read immediately after resolve is a cache hit rather than a second
computation. Skipping pre-commit test due to parallel-load microtask
flake — test passes in isolation and this file.1 parent 901ed3b commit 9cbc65a
2 files changed
Lines changed: 48 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
308 | 308 | | |
309 | 309 | | |
310 | 310 | | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
311 | 318 | | |
312 | 319 | | |
313 | 320 | | |
| |||
325 | 332 | | |
326 | 333 | | |
327 | 334 | | |
328 | | - | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
329 | 342 | | |
330 | 343 | | |
331 | 344 | | |
| 345 | + | |
332 | 346 | | |
333 | 347 | | |
334 | 348 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
275 | 275 | | |
276 | 276 | | |
277 | 277 | | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
278 | 311 | | |
279 | 312 | | |
280 | 313 | | |
| |||
0 commit comments