Dynamic Route Cache
Answered
B33fb0n3 posted this in #help-forum
B33fb0n3OP
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:
The revalidate does not work. Maybe because of the docs:
How can I cache the pages from the route?
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?
21 Replies
or
export const dynamic = 'force-static'Answer
@aardani or `export const dynamic = 'force-static'`
B33fb0n3OP
that worked!
I just added it like that and now it's static generated but revalidate after 2 minutes. Thats exactly what I want, thanks! â¤ï¸
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'`
B33fb0n3OP
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?
B33fb0n3OP
I just checked and it’s only in prod
Where is the consolelog located?
@aardani Where is the consolelog located?
B33fb0n3OP
On the serverside. You can see it here: https://nextjs-forum.com/post/1144282281796714517#message-1144282281796714517
And where is getpageData called?
B33fb0n3OP
Any ideas @aardani ? 🥴
No sorry
Ill take a look at it more later
B33fb0n3OP
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
B33fb0n3OP
Alright ðŸ‘
this is an ✅ answered post, could you make a new post with the updated question?
@joulev this is an ✅ answered post, could you make a new post with the updated question?
B33fb0n3OP
Yeah, done right in this moment ðŸ‘
the ✅ answered tag does discourage people from joining in, and from my pov the issue is indeed resolved. i recommend making a new post