Good practise for migration to cache components #87424
Unanswered
brunorzn
asked this question in
App Router
Replies: 1 comment 5 replies
-
|
Mmm I see, take a look at: https://nextjs.org/docs/app/api-reference/file-conventions/dynamic-routes#with-cache-components Looks like I'll need to move a few things around. This section, https://nextjs.org/docs/app/api-reference/functions/generate-static-params#with-cache-components points you to:
And the rest under is about Route Handlers, and Route Handlers with Cache Components |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
The cache components feature was long awaited for me, as it enables some very good use cases.
Unfortunately, migrating to it is quite painful. I find it hard to understand the clear production-ready good practices from the documentation.
My main use case is building mostly static sites, with potential dynamic segments, that get a lot of traffic and are based on a rate-limited CMS.
With the previous Next version and generateStaticParams, everything was very simple and worked very, very well.
Reading the documentation, using “use cache” felt very natural and promising, as I was used to use unstable_cache() when necessary. That was until I read about the “use cache: remote” directive, explained much, much lower down in the docs...
It is hard to understand how to achieve the exact same behavior as before, and what the best way to do so is. We should we put “use cache: remote” ? At the page or layout level? This feels very unnatural.
Another example, the generate static params documentation mentions a cache component example that displays a “use cache” directive within a route, and presents it as “optimal caching”. However, since “use cache” is in memory, deploying this to a serverless environment like Vercel means the fetch call will be made many times, hitting our rate limits and increasing our bills. Sounds far from optimal caching to me.
Even when using “use cache: remote”, I still see a lot of calls to that rate-limited API being made, even though I have set the following in the Next config:
How can I guarantee that my fetch calls won't be made twice, unless I manually call something like revalidateTag ?
Thanks
Beta Was this translation helpful? Give feedback.
All reactions