Dynamic routes: caching
Answered
Bicknell's Thrush posted this in #help-forum
Bicknell's ThrushOP
Hi there,
I was wondering if there is any way to apply caching to dynamic routes, say revalidate on 10 minutes. I've tried a lot but it doesn't seem it's possible, but I am having a hard time believing that to be honest..
Some context: I am using Next to render blogs, which is a dynamic route. The slug is fetched and then tossed to apollo client for GraphQL. I want to use SSR to be able to have the blogs indexed by search engines.
Thanks in advance,
Thijmen
I was wondering if there is any way to apply caching to dynamic routes, say revalidate on 10 minutes. I've tried a lot but it doesn't seem it's possible, but I am having a hard time believing that to be honest..
Some context: I am using Next to render blogs, which is a dynamic route. The slug is fetched and then tossed to apollo client for GraphQL. I want to use SSR to be able to have the blogs indexed by search engines.
Thanks in advance,
Thijmen
Answered by Bicknell's Thrush
I see that adding this fixes it it seems:
However, I was unable to find this in the documentation.
export const generateStaticParams = () => {
return []
}However, I was unable to find this in the documentation.
15 Replies
Bicknell's ThrushOP
I mean, even this post is being hit by cache if I look at the headers: https://nextjs-forum.com/post/1225069834996416623
Bicknell's ThrushOP
I see that adding this fixes it it seems:
However, I was unable to find this in the documentation.
export const generateStaticParams = () => {
return []
}However, I was unable to find this in the documentation.
Answer
Bengal
Wow you are a saviour. I can't believe that this is not properly documented. We have a whole essay with charts, explaining less important caching mechanisms like memoization and fetch cache, and we have almost no real world guidance for the arguably most important one - controlling the page-level CDN cache.
Thanks you 🙏
Thanks you 🙏
Bengal
Yeah sure, the docs exist, but what I'm saying is - this is literally the most impactful part of caching. We have 3 sentences about it. And they don't even paint a clear picture.
By comparison we have a whole essay on router caching and react in-request memoization. 😦
By comparison we have a whole essay on router caching and react in-request memoization. 😦
This part explains about per-page cache
Bengal
Percicely what I was pointing to - at no point does that whole essay explain that returning an empty array will result in this behaviour.
Bengal
lol what are you talking about? At what point does
dynamicparams state that generateStaticParams has a special magic return value of [] that causes the page to drop into "SSG without prerendering but with static CDN cache"?[] is not a special magic return valueit literally just means empty array
means nothing to generate at build time...