#Metadata makes two db queries?

30 messages ยท Page 1 of 1 (latest)

fiery craterBOT
#

๐Ÿ”Ž 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)

stark dust
stark dust
#

this will memoize the function only for the duration of the request

#

so you don't need to worry about revalidating it

#

yeah with unstable_cache you can basically use the same cache stuff from fetch

#

you use react's cache when you just want to avoid rerunning the same function from different places for the same request

#

I think it depends on how you are using redis, in my experience unstable_cache is a bit unreliable

#

but its still experimental so they will probably fix it

#

yeah thats fine

stark dust
#

yeah the keyParts is used by next.js to store and find your cached value, the tags are necessary if you want to manually revalidate it with revalidateTag

#

they don't need to be the same, in your example I would use ["paste", slug] as the keyParts, but the tag is fine as a single string

#

what do you mean you can't access the variable? ๐Ÿค”

#

is the variable defined?

#

ah true you don't have it yet

#

no thats a perfectly valid question

#

and I have no idea how to do it with a dynamic variable like that ๐Ÿ˜…

#

I recommend avoiding this function until it gets stable, the docs are very lacking at the moment

#

in this situation I would use the route segment config for the post pages

#

you can then use react's cache function to avoid querying the db twice

#

and revalidatePath to revalidate a specific page by its path

#

it looks like calling unstable_cache from within the function is a valid use case so this should be fine

#

oh probably not, most db drivers aren't supported on the edge runtime unfortunately

#

np meowthumbsup

toxic sparrow
#

the docs for unstable cache are definetely lacking, but kapa ai helped in #1089389297548931182 so if you don't already use that you should try it out

stark dust
#

cool, thanks for confirming it works! I will give it another try in the future ๐Ÿ‘€

fiery craterBOT
#
โœ… Success!

This question has been marked as answered! If you have any other questions, feel free to create another post

Jump to answer

[Click here](#1202000296965054597 message)