Set maxAge to forever?
ablakey opened this issue · 3 comments
I've tried to set maxAge: Number.POSITIVE_INFINITY
but that does not get respected as "forever".
Is there a way to tell the cache to simply never invalidate (because I know I'm serving up immutable records at these URLs)?
Hey @ablakey
I don't understand why it does not work 🤔
maxAge
is being added to Date.now()
to get the actual expiration date.
Doing Date.now() + Number.POSITIVE_INFINITY
becomes Infinity
and Infinity < Date.now()
is always false
so the cache should end up never expiring.
I will add a test to actually verify the behavior.
Could you share how you setup axios-cache-adapter? Is it in the browser/node? Using a specific store?
Cheers
You may also put axios-cache-adapter in debug mode by passing debug: true
option. You will get extra logs to analyze cache behavior 🙂
More specifically you should get cache-hit
logs for your URLs configured with maxAge: Number.POSITIVE_INFINITY
. If not then there is definitely an issue somewhere.
Thanks for the tips.
I can reproduce and with debug I get cache-stale
.
Configuration
- axios-cache-adapter: 2.7.3
- Browser (Chrome 89)
- Store: memory
import { setup } from "axios-cache-adapter";
export const axiosInstance = setup({
baseURL: BASE_URL,
withCredentials: true,
cache: {
maxAge: Number.POSITIVE_INFINITY,
debug: true,
exclude: {
query: false,
},
},
headers: { Accept: `application/json; version=${API_VERSION}` },
});
Debug Logs
[axios-cache-adapter] uuid http://0.0.0.0:8000/floor_datasets/998d8369-8a1e-418e-94af-754f62e9098b/
[axios-cache-adapter] cache-miss /floor_datasets/998d8369-8a1e-418e-94af-754f62e9098b/
[axios-cache-adapter] uuid http://0.0.0.0:8000/floor_datasets/998d8369-8a1e-418e-94af-754f62e9098b/
[axios-cache-adapter] Request config for /floor_datasets/998d8369-8a1e-418e-94af-754f62e9098b/ {maxAge: Infinity, limit: false, store: MemoryStore, key: ƒ, invalidate: ƒ, …}
[axios-cache-adapter] cache-stale /floor_datasets/998d8369-8a1e-418e-94af-754f62e9098b/
If I keep the exact same config and context, and set maxAge to a finite number like 1000 * 60 * 60
it works fine.
Let me know how else I can help you reproduce and debug this issue.