Next.js Discord

Discord Forum

how to revalidate a cached function (get some data in the db using cache(...) ) ?

Answered
American Crocodile posted this in #help-forum
Open in Discord
Avatar
American CrocodileOP
revalidate a cached function (get some data in the db using cache(...) )
Answered by American Crocodile
looks like it does work with this
Image
View full answer

17 Replies

Avatar
joulev
revalidatePath()
Avatar
American CrocodileOP
i've try to call revalidatePath() with a fetch, it does not work
Image
Avatar
joulev
Then that means revalidatePath() is buggy or you did it incorrectly
Avatar
American CrocodileOP
Image
Avatar
joulev
Looks sus, shouldn’t it be /api/revalidate with a slash at the front
Avatar
American CrocodileOP
it does not throw an error ?
(im a newbie sorry)
Avatar
joulev
This did console.log correctly right
With path being the correct path and all
Avatar
American CrocodileOP
hey it does
Avatar
joulev
Then revalidatePath is buggy i think
Though it works for me
Avatar
American CrocodileOP
Image
Avatar
American CrocodileOP
looks like it does work with this
Image
Answer
Avatar
American CrocodileOP
(server actions)
Avatar
Manx
There is so little information on the web regarding how cache() works. So does cache only de-duplicate functions per path? I have a lot of API calls through a library that could be deduplicated on an authenticated page (so it renders dynamically depending on the logged in user), but the data could be refreshed updated externally. My questions are:

- I created a function that deduplicates based on some key (e.g. id: 1) as the parameter, is this deduplicated between requests for this data from different users?
- If the function is also used in other paths, when calling revalidate, does it revalidate all the cache of the function for all routes that depend on it?