Next.js Discord

Discord Forum

Please help! fetch (with 'force-cache') in client component. How to reset cache??

Answered
West African Lion posted this in #help-forum
Open in Discord
West African LionOP
Hi, please help me! I am making a fetch call to get some data from DB, but i want it cached so it's cheaper on the server and also faster. But when that data changes, I want the cache to be reset/revalidated. revalidateTags from docs doesn't seem to work. Please help, how do I reset cache ?
Answered by Anay-208
use unstable cache
View full answer

25 Replies

Northeast Congo Lion
use revalidate
fetch(url, {
  next: {
    revalidate: <time_in-seconds>
  }
})
afaik, force-cache will force it to cache and only be invalidated/refreshed at a new build.
West African LionOP
that doesn't work in client component 4 some reason
I'm asking to revalidate only when data changes, like after a user donates
in DOCS it says that is done with revalidateTags, but that also doesn;t work..... sorry and thanks
@West African Lion I'm asking to revalidate only when data changes, like after a user donates
not add anything in cache, it'll remained cache, and in next options, add a tag
and revalidate that Tag
West African LionOP
I think this is what you mean, will try thanks
yup
and when a payment is done, revalidate it
is this code client side?
West African LionOP
yes, timed revalidate doesn't work, and revalidateTag() either
is this a "use client" component?
West African LionOP
yes sir
It won't work on use client. You'll have to add cache directly to /api/cache/[idk_some_id]/route.[ts|js]
@West African Lion I think this is what you mean, will try thanks
You don't need to add anything related to cache here, it'll only work for that 1 specific user.
West African LionOP
ok, I can cache and re-validate on server? do you please have docs ?
Answer
and add a tag to it
and revalidate it
West African LionOP
ok, thank you very much!
If it works, mark my message as a solution