#cacheLife: never serve stale data

1 messages · Page 1 of 1 (latest)

late relic
#

A frustration I have with the current NextJS cache behavior is that there is no built in way to have a time-based cache without serving stale data. For my use case, this is not valid.

From what I can tell, the new (upcoming) "use cache" directive and cacheLife function may solve my problem, but I can't tell for sure from the docs.

If I did the following:

// /app/some-route/route.js
"use cache";
export const GET = async (req) => {
  cacheLife({
    stale: 30, // 30 seconds
    revalidate: 30, // 30 seconds
    expire: 30, // 30 seconds
  });
  // route handler logic
};

What is the behavior? Specifically, will it server stale data at the first request after expiry, or will it switch to dynamic immediately after the data is stale (never serving stale data)?

jolly hedgeBOT
#

🔎 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)