#unstable_cache fetches twice every build on Vercel

21 messages · Page 1 of 1 (latest)

true wyvern
#

I posted this on Discussions but no one answered this so hopefully someone here could help me.
https://github.com/vercel/next.js/discussions/60704

unstable_cache is supposed to act the same as Data Cache but it's updated every build on Vercel. Tried the same function that is wrapped in it with a route handler won't be updated unless manually revalidated. Is this intended?

PS: my problem is that unstable_cache won't be cached across deployments and it fetches twice always

GitHub

Repo: https://github.com/roxizhauk/test-unstable-cache The data cached by unstable_cache is updated every build on Vercel, querying to my database on PlanetScale TWICE (always). Is this an expected...

stone turtleBOT
#

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

tardy island
#

im not sure what your issue is, but there are 2 things i will add:

  1. unstable_cache doesn't seem to dedup yet, so if your running it a tthe same time, you may need to wrap it in react cache
  2. the fetch calls the db does became forced to be uncached (as it can be bad if not manualy done), but that doesn't mean the unstable_cache isn't caching
true wyvern
tardy island
#

oh that is intresting because i too thought it was an independent cache from deployment (but if you change the function then ofc it will change)

#

after all as you said, its in the data cache

true wyvern
#

Yeah, and I tried the function I made with a route handler so that it works as Data Cache. It won't be updated across deployments so I believe the function isn't the problem.

Oh, and being fetched TWICE is another problem, sorry I should've been more clear

#

So my problem is that unstable_cache won't be cached across deployments and it fetches twice always

tardy island
#

wait the function gets ran twice 😭

tardy island
true wyvern
#

the same one. I've observed PlanetScale executed the same query twice

#

BUT it won't happen in a route handler meaning the query is done once

tardy island
#

and to be sure, is this a vercel issue or nextjs (ie does local dev do same thing)

true wyvern
#

In local build, it still fetches twice in the initial build but the cache seems not updated in another build (becasue the query wouldn't be fired in PlanetScale). so is this to be a Vercel's issue for not fully supporting unstable_cache?

tardy island
#

intresting

#

if you make the page dynamic export const revalidate = 0, can you see how well it caches

#

maybe the build is just weird, so im wondering if its more sane if not using it then

#

or maybe the build is doing something weird with the page, and maybe wrapping the unstable cache in react cache, might make it once

true wyvern
#

It's weird. With export const revalidate = 0, tried rm -rf .next && next build && next start it only fetched once

tardy island
#

hmm

true wyvern