#revalidate 0 on unstable_cache

62 messages · Page 1 of 1 (latest)

mossy sparrow
#

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.

stoic havenBOT
#

🔎 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)

strong lantern
mossy sparrow
strong lantern
#

by setting revalidate to 0 in route segment mean it is always dynamic render

#

are you trying to make the page dynamic?

mossy sparrow
#

setting revalidate 0 on page didnt work too 😦

strong lantern
mossy sparrow
#

i want a data refresh each time i visit the path

strong lantern
#

then you should make the page dynamic

mossy sparrow
#

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

strong lantern
#

revalidatePath after mutation with revalidate 0 doesn't work?

mossy sparrow
#

nope

#

i mean, revalidatePath yes

#

but if i refresh the page and mutated the data on db directly, dont refresh the cached data

strong lantern
#

this is how revalidate work

mossy sparrow
#

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.

strong lantern
#

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

mossy sparrow
#

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.

strong lantern
#

it is working for me

#

the page is dynamic if I have export const revalidate = 0

mossy sparrow
#

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.

strong lantern
#

do you have a reproduction?

#

are you using unstable_cache with export const revalidate?

mossy sparrow
strong lantern
mossy sparrow
#

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?

strong lantern
#

if you have revalidate =0, the page is dynamic but the data is still cached by unstable_cache

mossy sparrow
#

i mean, in practice its the same

strong lantern
#

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

mossy sparrow
strong lantern
#

then you will need to use revalidateTag to update the cache after you mutate the data

mossy sparrow
#

yeah, i just want both, revalidate when accessing the route and when I mute the data

strong lantern
#

if you want the page get updated after you mutate the data in db, you should make the page dynamic

mossy sparrow
#

revalidateTag works fine

#

cache and force-dynamic works well?

strong lantern
#

you mean export const dynamic = "force-dynamic" + unstable_cache?

mossy sparrow
#

yeah

#

thats its

mossy sparrow
#

so it will not be updated when I visit the site

strong lantern
mossy sparrow
#

revalidate: 0.1, yeah, thats what i need

#

there is a big difference between 0.1 and 1 ?

strong lantern
#

oh can't set it 0.1 now

#

need at least 1

strong lantern
mossy sparrow
#

hmmmm yeah, thats bad but i think its the only way currently

strong lantern
#

because revalidate only happen when you visist the page

strong lantern
#

or just run revalidateTag after you update the data

mossy sparrow
#

I will try to find a solution to this

#

ty a lot!!