Unstable_cache and dynamic functions
Unanswered
Florian posted this in #help-forum
FlorianOP
Does
In my case, I'm loading the session data in the root layout. My trending topics are not cached when I
unstable_cache not work if a dynamic function is called on that page?In my case, I'm loading the session data in the root layout. My trending topics are not cached when I
npm run build.27 Replies
@Florian Does `unstable_cache` not work if a dynamic function is called on that page?
In my case, I'm loading the session data in the root layout. My trending topics are not cached when I `npm run build`.
It should work. It works fine for me. Though in your code revalidateTag("trends") won’t work
@joulev It should work. It works fine for me. Though in your code revalidateTag("trends") won’t work
FlorianOP
Does revalidatePath clear the unstable_cache?
Hmm good question, I don’t know for sure but I think yes
FlorianOP
That's tricky then because I need to update the feed 🤔
Since you are unstable_cache’ing anyway, why not revalidateTag?
@joulev It should work. It works fine for me. Though in your code revalidateTag("trends") won’t work
To tag it you need to put it in the tags array not the key part array. So
[],
{ revalidate: …, tags: ["trends"] }
[],
{ revalidate: …, tags: ["trends"] }
@joulev Since you are unstable_cache’ing anyway, why not revalidateTag?
FlorianOP
Because the feed needs revalidation, not the trends. But I tried it out without revalidatePath and it still shows the latest value on every refresh.
Maybe tag the feed too and revalidate it?
Could you give me a reproduction example? Instead of querying a database you could generate a random string for example in that reproduction repo
FlorianOP
Well I don't know what is causing this and what I would have to reproduce
@joulev Maybe tag the feed too and revalidate it?
FlorianOP
I would have to wrap all my Prisma calls into
unstable_cache which seems like a readability nightmare. Maybe I need to cache my data somewhere else.@Florian I would have to wrap all my Prisma calls into `unstable_cache` which seems like a readability nightmare. Maybe I need to cache my data somewhere else.
Hmm it’s actually not that unreadable. I unstable_cache every query in my app and it still is very readable
FlorianOP
I would consider it if it worked. But even without
revalidatePath it didn't cache. I must be doing something wrong somewhere else on that page.Hm. Could you give me a minimal reproduction repository? Your code looks fine so without the reproduction repo I can’t really make any guesses
https://l.joulev.dev/mrr
https://l.joulev.dev/mrr
inside unstable_cache or just the page?
@ᴉuɐpɹɐɐ where is the dynamic function?
FlorianOP
I fetch the logged-in user in the
layout.tsx (which uses cookies())From there I pass it to a sessionprovider
@Florian I fetch the logged-in user in the `layout.tsx` (which uses `cookies()`)
what do you mean when you said that its not cached?
do you want it to become static page? is it not working on
npm run start?@ᴉuɐpɹɐɐ do you want it to become static page? is it not working on `npm run start`?
FlorianOP
I want this one component to be static for 3 hours (using
unstable_cache + revalidate)FlorianOP
It seems that unstable_cache works on Vercel but not in a local build
@Florian It seems that unstable_cache works on Vercel but not in a local build
thats weird, is it only in latest version?
FlorianOP
Sorry false alarm
It doesn't just work at all right now
phew