Skip to content
Discussion options

You must be logged in to vote

setupCache() only affects the Axios instance passed to it, but caching is enabled by default for every eligible request made through that instance. You do not need a second instance just to use opt-in caching.

Disable caching globally and enable it only for selected requests:

const api = setupCache(axios.create({ /* headers */ }), {
  enabled: false
});

const response = await api.get("/cached-endpoint", {
  cache: {
    enabled: true,
    override: true,
    hydrate(cache) {
      render(cache.data); // existing cached payload
    }
  }
});

render(response.data); // fresh network payload

override: true makes a network request even while the stored response is fresh. hydrate provides the…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by arthurfiorette
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #1002 on April 22, 2025 08:48.