Revalidate cache only after a certain fixed duration [Q&A/Feature Request] #2069
Unanswered
roch-numbered
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
I'm working on a dashboard where I'm making requests to supabase to get user's infos. I'm saving the list of accounts into LocalStorage and I'd like to revalidate the data only after a certain amount of time AND if the user loads in a new session.
A step by step description of my use case
Saying
CACHE_DURATION = 300_000 // 5 * 60 * 1000 = 5 minutes
.CACHE_DURATION
delay is not passed, 2nd connection happens 3 minutes after the 1st one, data are pulled from LocalStorage and no network calls are made.My issue
From what I understand of SWR, it's not currently possible to specify a
cacheDuration
delay that would automatically check if saved data needs to be updated.The
refreshInterval
is a half-solution has it's valid only through the session and not across time. Plus it keep fetching even if data are already saved. With the ability to give a function torefreshInterval
it would be possible to fetch only one time. But still, it does check across sessions.The #1708 PR seems to brought a first step to a solution with the
updatedAt
value.Possible workaround
From discussion #2013, it seems that I have to handle the expiration manually. Can someone confirm that to me please?
My implementation:
Feature Request
As SWR is already handling cache and revalidation, would it be possible to handle the expiration mechanism directly inside the library?
Beta Was this translation helpful? Give feedback.
All reactions