Next.js Discord

Discord Forum

Dynamic Route Cache

Answered
B33fb0n3 posted this in #help-forum
Open in Discord
Hey, I have a catch all route created like app dir -> anotherpage -> [[...page]] -> page.js.
In this page.js I would like to render data and I fetch it like that:
export const revalidate = 120;

export const getPageData = cache(async () => {
    console.log("getPageDataFetchCalled")
    // const {data} = await API.graphql({query: listTodos});
    return {data: false};
})

export default async function Page({params}) {
    const data = await getPageData();

    return (
        <>
            <h1>Hello World!</h1>
            <p>{params.page[0]}</p>
        </>
    )
}

The revalidate does not work. Maybe because of the docs:
If the segment is dynamic, the output of the request will not be cached and will be re-fetched on every request when the segment is rendered.
Can I somehow cache them, because the examples show that there is an id and also the id is "dynamic". The same in my case. I have a Route (app dir -> anotherpage -> [[...page]] -> page.js) and only the ...page is dynamic

How can I cache the pages from the route?
Answered by aardani
or export const dynamic = 'force-static'
View full answer

21 Replies

or export const dynamic = 'force-static'
Answer
@aardani or `export const dynamic = 'force-static'`
that worked!
export const revalidate = 120;
export const dynamic = 'force-static'

I just added it like that and now it's static generated but revalidate after 2 minutes. Thats exactly what I want, thanks! ❤️
@aardani or `export const dynamic = 'force-static'`
do you know, why the console.log is called 2 times when it's revalides? 🤔
Hmmm not sure, is it in dev or prod?
@aardani Hmmm not sure, is it in dev or prod?
I just checked and it’s only in prod
Where is the consolelog located?
@aardani Where is the consolelog located?
And where is getpageData called?
@aardani And where is getpageData called?
Inside the component
Any ideas @aardani ? 🥴
No sorry
Ill take a look at it more later
Yea it persists. Take your time but please don’t forget me 💫
bruh just keep bumping im sure someone will get to you
idk if its an intended behavior or not
Alright 👍
this is an ✅ answered post, could you make a new post with the updated question?
the ✅ answered tag does discourage people from joining in, and from my pov the issue is indeed resolved. i recommend making a new post