How can I force to the SWR don't hit the server if has already cached the key? (with a 15 minutes interval) #570
Replies: 4 comments 4 replies
-
you can use the cache api to detect if the corresponding data is in the cache already import {cache} from 'swr'
useSWR(key, /*. .. */)
cache.has(key) // return `true` or `false` |
Beta Was this translation helpful? Give feedback.
-
I would move this to the fetcher, inside y check if data is already in cache and return it, also keep track somehow (another cache key you manually define maybe) when it was updated so you can check if it was longer than 15min to do the actual fetch or not to return cached value. |
Beta Was this translation helpful? Give feedback.
-
You could also let the brwoser cache it by using a |
Beta Was this translation helpful? Give feedback.
-
Great guys, thanks! I'm doing some POCs yet. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi guys,
I'm testing the swr and I want that the swr get data from the server only once, at the first page view, and then, only reload the data/cache after 15 minutes...
I noriced by the web dev console that the swr hit the server all the times when I view a page, even when the response is cached.
Can anyone helpe me?
Thanks so much!
Beta Was this translation helpful? Give feedback.
All reactions