Skip to content
This repository has been archived by the owner on Feb 28, 2023. It is now read-only.

Set maxAge to forever? #242

Open
ablakey opened this issue Mar 25, 2021 · 3 comments
Open

Set maxAge to forever? #242

ablakey opened this issue Mar 25, 2021 · 3 comments

Comments

@ablakey
Copy link

ablakey commented Mar 25, 2021

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)?

@ghost
Copy link

ghost commented Mar 30, 2021

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

@ghost
Copy link

ghost commented Mar 30, 2021

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.

@ablakey
Copy link
Author

ablakey commented Mar 30, 2021

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant