Skip to content

Honoring Cache-Control Header #559

Discussion options

You must be logged in to vote

useSWR requires users to pass a fetcher function having the type signature (key: string) => Data | Promise<Data> to 'get' the data so therefore useSWR itself doesn't know anything about your cache headers, just the data and the key it belongs to.

useSWR will cache the data until new data comes back to replace it, with fetches being triggered by revalidation events such as revalidateOnMount, revalidateOnFocus, or manual mutate invalidations, for example.

When swr tries to revalidate/fetch the resource via your fetcher caused by one of those events, your fetcher could make a HTTP request and then it'll go through your browsers HTTP cache at that point.

Going back to your particular use case…

Replies: 2 comments 5 replies

Comment options

You must be logged in to vote
2 replies
@neilchaudhuri
Comment options

@lukebarton
Comment options

Answer selected by neilchaudhuri
Comment options

You must be logged in to vote
3 replies
@lukebarton
Comment options

@neilchaudhuri
Comment options

@sergiodxa
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants