Dynamic rendering do not refetch certain queries.
Answered
Siamese Crocodile posted this in #help-forum
Siamese CrocodileOP
Hi my app is dynamically rendered because of checking cookies for user authentication in main layout (it makes all pages dynamic).
Some pages have data that I do not want to fetch on every request like cms content but I want to fetch dynamically other data that this page uses.
How can I achive it?
Some pages have data that I do not want to fetch on every request like cms content but I want to fetch dynamically other data that this page uses.
// page.tsx
// dynamic rendered page
export async function Page(){
// fetch it once during build and revalidate on demand or every 1h or so
const cmsData = await getCmsData()
const users = await getUsers() // fetch it dynamically and do not cacheHow can I achive it?
20 Replies
@Siamese Crocodile Hi my app is dynamically rendered because of checking cookies for user authentication in main layout (it makes all pages dynamic).
Some pages have data that I do not want to fetch on every request like cms content but I want to fetch dynamically other data that this page uses.
ts
// page.tsx
// dynamic rendered page
export async function Page(){
// fetch it once during build and revalidate on demand or every 1h or so
const cmsData = await getCmsData()
const users = await getUsers() // fetch it dynamically and do not cache
How can I achive it?
export async function getCmsData() {
await fetch("", { next: { revalidate: 3600 // 1hr } })
}Siamese CrocodileOP
And when getCmsData doesnt use fetch
but graphql-request
or prisma directly?
@Ray
@Ray
Answer
Siamese CrocodileOP
So when someone goes to
Then when another person enters
/home and fetches the cms dataThen when another person enters
/home we have cms data in cache?and its not fetched?
yes
Siamese CrocodileOP
Sure
Thanks
Siamese CrocodileOP
@Ray what about cache from react
I can't understand a difference
@Siamese Crocodile <@743561772069421169> what about cache from react
cache from react is mainly for dedup, it doesn't store the result to data cache
Siamese CrocodileOP
From my understanding next stores data in server cache and react only stores IT client side
@Siamese Crocodile So when someone goes to `/home` and fetches the cms data
Then when another person enters `/home` we have cms data in cache?
Siamese CrocodileOP
So that woudlnt work
when the request is finished, the data is gone
Siamese CrocodileOP
Aight
Siamese CrocodileOP
Thanks!