#How to Prevent Caching Errors when using "use cache" in Next.js 15?

1 messages · Page 1 of 1 (latest)

queen otterBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)

radiant jolt
#

for queries with errors, I tend to set different revalidation time. I think fetch cache does that by default, but if you use custom cache, try doing something like this:

// Your code
if(error)
  cacheLife('seconds')
else 
  cacheLife('default')

You can also create custom cacheLife profiles in next.config.ts.

Read more here: https://nextjs.org/docs/app/api-reference/functions/cacheLife

Learn how to use the cacheLife function to set the cache expiration time for a cached function or component.

#

you can also set the cache profile inline if this is a one-off handling:

  cacheLife({
    stale: 0,
    revalidate: 0,
    expire: 0,
  })
muted acorn
#

WOW! Such an elegant and simple solution—I love it. I really appreciate your help! ❤️

radiant jolt
#

Don't forget to mark the question as answered once you verify that it does exactly what you'd expect 🙂

muted acorn
#

how can I do that?

radiant jolt
#

Take a look at the first message here - help-forum has a bot that contains info about marking something as solution. Simply right-click on the message that solves your problem, go to Apps and use Mark Solution option

strange solstice
queen otterBOT