Hello everyone,
I'm trying to use unstable_cache to add a tag to a function that doesn't use fetch but does a sql query. I would like to add revalidate 0 but every time I do it I get the following error: "Error: Invariant revalidate: 0 can not be passed to unstable_cache(), must be "false" or "> 0"". I can't use unstable_noStore either because it doesn't work, how can I make it refresh every time I enter the path or call revalidateTag.
#revalidate 0 on unstable_cache
62 messages · Page 1 of 1 (latest)
🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord
🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize
✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)
can you try to set it to 1?
right now im using 1, I understand that 0 and 1 are practically the same, no?
by setting revalidate to 0 in route segment mean it is always dynamic render
are you trying to make the page dynamic?
setting revalidate 0 on page didnt work too 😦
what is not working?
i want a data refresh each time i visit the path
then you should make the page dynamic
with revalidate 0, the data remains cached
only workaround i found its working is set revalidate 1 on unstable_cache
and use a tag to revalidate if i mutate the data
revalidatePath after mutation with revalidate 0 doesn't work?
nope
i mean, revalidatePath yes
but if i refresh the page and mutated the data on db directly, dont refresh the cached data
this is how revalidate work
I want the same functionality as getServerSideProps, whenever I make a request, it will revalidate the data. currently using cache and revalidate 0 does not work, the only way I have found is to use revalidate 1.
getServerSideProps = export const dynamic = "force-dynamic"
if you have export const revalidate = 1, and update the data in db.
refresh the page should still show cached data
refresh again should show new data
yes, it should work but in practice it doesn't, I imagine it's because of the unstable_cache functionality, it's not quite right yet.
which is not working?
it is working for me
the page is dynamic if I have export const revalidate = 0
this use case does not work, at least for me:
- function to return cached data with tag so I can revalidate it when I modify something.
- export const revalidate = 0 in page to force it to be dynamic
I run a query on the database directly, refresh the web and it doesn't return the latest data, it caches the previous data.
do you have a reproduction?
are you using unstable_cache with export const revalidate?
hmmmm right now no bc its not finished so i cant upload to repo 😦
yeah
that's why
i cant use unstable_cache with revalidate?
then how could I add a tag to a function to be able to revalidate it if it does not use fetch?
if you have revalidate =0, the page is dynamic but the data is still cached by unstable_cache
yeah, but i cant set revalidate 0 to unstable_cache, i need to use 1
i mean, in practice its the same
if you want 0 on unstable_cache which mean you don't want it to cache at all
so you should make the page dynamic
im using unstable_cache to add a revalidateTag to the function that does not use fetch
then you will need to use revalidateTag to update the cache after you mutate the data
yeah, i just want both, revalidate when accessing the route and when I mute the data
if you want the page get updated after you mutate the data in db, you should make the page dynamic
wdym?
you mean export const dynamic = "force-dynamic" + unstable_cache?
same as this
so it will not be updated when I visit the site
no, you need either revalidateTag or with revalidate: 0.1 in unstable_cache
revalidate: 0.1, yeah, thats what i need
there is a big difference between 0.1 and 1 ?
but you will have to visit the page twice to get latest data
hmmmm yeah, thats bad but i think its the only way currently
because revalidate only happen when you visist the page
yes this is how ISR work
or just run revalidateTag after you update the data