Next.js Discord

Discord Forum

Conditional cacheLife profiles with use cache

Unanswered
Iridescent shark posted this in #help-forum
Open in Discord
Iridescent sharkOP
As stated I wish to apply different cacheLife profiles conditionally with "use cache". Is this possible?

I've been playing with the idea in my head of nesting components with "use cache" and different cacheLife profiles (https://nextjs.org/docs/app/api-reference/functions/cacheLife#nested-usage-of-use-cache-and-cachelife) to achieve this. I'm thinking of conditionally rendering a sub component with its own shorter cacheLife profile whenever I want the page to have a shorter cache life. Is this a good idea or is it frowned upon? Honestly not even sure if it will work, I guess it depends on whether the cacheLife profile in the sub component is fetched statically or at "run time". I might also get the Cannot access Math.random() while prerendering error I guess

0 Replies