Swr: global cache?

Created on 28 Oct 2019  路  2Comments  路  Source: vercel/swr

Is the key cache global? How does it handle conflicts if it's used in multiple contexts?

question

All 2 comments

Yes, the key cache is global across all useSWR calls.

How does it handle conflicts

Your cache keys shouldn't conflict, otherwise the cache isn't very useful. We've found that using the URL of the API you're calling to be good keys.

used in multiple contexts

If you have useSWR calls in multiple places that use the same key, the data is shared and updated in all contexts. This makes it easy to synchronize data between multiple pages that use the same data sources.

Yes, the key cache is global across all useSWR calls.

useSWR share states between multiple calls in same next.js page.
but, useSWR does NOT share states between multiple next.js pages,

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sergiodxa picture sergiodxa  路  4Comments

tiagocorreiaalmeida picture tiagocorreiaalmeida  路  3Comments

frdwhite24 picture frdwhite24  路  4Comments

baoduy picture baoduy  路  4Comments

bcomnes picture bcomnes  路  3Comments