revalidate 0 on unstable_cache
Unanswered
fran posted this in #help-forum
franOP
Hello everyone,
I'm trying to use
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.61 Replies
@Ray can you try to set it to 1?
franOP
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 renderare you trying to make the page dynamic?
franOP
setting revalidate 0 on page didnt work too 😦
@fran setting revalidate 0 on page didnt work too 😦
what is not working?
franOP
i want a data refresh each time i visit the path
then you should make the page dynamic
franOP
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?
franOP
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
franOP
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
refresh the page should still show cached data
refresh again should show new data
export const revalidate = 1, and update the data in db.refresh the page should still show cached data
refresh again should show new data
franOP
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.
it is working for me
the page is dynamic if I have
export const revalidate = 0franOP
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.
- 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?@Ray do you have a reproduction?
franOP
hmmmm right now no bc its not finished so i cant upload to repo 😦
@fran yeah
that's why
franOP
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
@Ray if you have revalidate =0, the page is dynamic but the data is still cached by unstable_cache
franOP
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 allso you should make the page dynamic
@Ray so you should make the page dynamic
franOP
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 datafranOP
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
franOP
revalidateTag works fine
cache and force-dynamic works well?
you mean
export const dynamic = "force-dynamic" + unstable_cache?franOP
yeah
thats its
franOP
so it will not be updated when I visit the site
@fran so it will not be updated when I visit the site
no, you need either
revalidateTag or with revalidate: 0.1 in unstable_cachefranOP
revalidate: 0.1, yeah, thats what i need
there is a big difference between 0.1 and 1 ?
oh can't set it 0.1 now
need at least 1
@Ray 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
but you will have to visit the page twice to get latest data
franOP
hmmmm yeah, thats bad but i think its the only way currently
because revalidate only happen when you visist the page
@fran hmmmm yeah, thats bad but i think its the only way currently
yes this is how ISR work
or just run
revalidateTag after you update the datafranOP
I will try to find a solution to this
ty a lot!!
np