Incorrect condition on `canStale` & `max-stale` should handled by `headerInterpreter`.
OHcz opened this issue · comments
I suspect canStale has incorrect condition.
value.createdAt + value.ttl + value.staleTtl <= Date.now()
shoudl be value.createdAt + value.ttl + value.staleTtl >= Date.now()
Hey, canStale is used to ensure if we can use the calculated staleTtl or not. You can check it out on our tests.
Also, have you found any misbehavior alongside this? Maybe explaining your problem helps me understand where things may went wrong.
My usecase is to present stale version of data if available and not "too old" while always download updated data "in background".
Im using webpack 1.1.1.
Sending these headers from nginx+php server together with json data:
Cache-Control: max-age=0, stale-while-revalidate=86400, max-stale=86400
setupCache contains
storage: window.AxiosCacheInterceptor.buildWebStorage(localStorage, 'axios-cache')
cache looks like this
createdAt: 1685358992930 data: {,…} staleTtl: 86400000 state: "cached" ttl: 0
Thanks for your bug report, it indeed was a bug.
defaultHeaderInterpreter
should use the max-stale value if present.
canStale
really should've been using >=
instead of <=
.
Weird that it didn't break any tests.
You're up to a PR?
You're up to a PR?
Sorry, this is unfortunately not my field of expertise ;)
Fixed in 1.2.0