Next.js Discord

Discord Forum

how come this page is static rendering?

When I do npm run build, it shows static content for this route.
from what I know, data is only cached when using fetch,
but I'm not using fetch to access my database, shouldn't this be dynamic?
Answered by B33fb0n3
when you dont add request memo to your requests, then your requests are not memorized, yea. And that means, that the same call will be send even if you call the same function in different components.

You can create API endpoints to have cache in them, but fetching your own endpoints in RSC isnt that good ([read more](https://nextjs-faq.com/fetch-api-in-rsc)). So instead you can use unstable_cache (in the future the 'use cache' directive)
View full answer

9 Replies

@𝓒𝓱𝓪𝓶𝓹𝓪𝓰𝓷𝓮~❤ When I do npm run build, it shows static content for this route. from what I know, data is only cached when using fetch, but I'm not using fetch to access my database, shouldn't this be dynamic?
you are not using any dynamic function. And without any dynamic function it will be statically rendered. Even if you have build a connection to your DB and fetch data. If you want to have it dynamic add:
export const dynamic = 'force-dynamic'
@Asian black bear ~~That's the opposite~~
ah mb, thanks 👍
@𝓒𝓱𝓪𝓶𝓹𝓪𝓰𝓷𝓮~❤ hmm, I see, is there any caching behavior for this connection to my database? like data cache, or request memoization?
yes, for caching your can use unstable_cache (in the future the 'use cache' directive) as you are not using fetch in the background and for request memo you can use the React.cache(() => { your code }) to memorize them
@B33fb0n3 yes, for caching your can use `unstable_cache` (in the future the `'use cache'` directive) as you are not using fetch in the background and for request memo you can use the `React.cache(() => { your code })` to memorize them
just to make sure, if I don't add any of this, my database request won't have the behavior of request memoization?which I can call it in different component and avoiding sending multiple time?

should I make a API endpoints and use fetch to connect to my database instead? so it can automatically cached for me?
@𝓒𝓱𝓪𝓶𝓹𝓪𝓰𝓷𝓮~❤ just to make sure, if I don't add any of this, my database request won't have the behavior of request memoization?which I can call it in different component and avoiding sending multiple time? should I make a API endpoints and use fetch to connect to my database instead? so it can automatically cached for me?
when you dont add request memo to your requests, then your requests are not memorized, yea. And that means, that the same call will be send even if you call the same function in different components.

You can create API endpoints to have cache in them, but fetching your own endpoints in RSC isnt that good ([read more](https://nextjs-faq.com/fetch-api-in-rsc)). So instead you can use unstable_cache (in the future the 'use cache' directive)
Answer
happy to help