Skip to content

Does next-shared-cache support stale-while-revalidate? #489

Answered by better-salmon
alex-guoba asked this question in Q&A
Discussion options

You must be logged in to vote

Hey, @alex-guoba.

You can use the estimateExpireAge callback to estimate the expiration age of stale data. By default, the stale age is the same as the expiration age, which can cause long loading times when the data becomes stale. However, you can customize the expiration age or calculate it based on the stale age to improve loading times.

CacheHandler.onCreation(async () => {
  const handler = {
    // ...
  };
 
  return {
    handlers: [handler],
    ttl: { estimateExpireAge: (staleAge) => staleAge * 10 }, // 10 time more than stale age
    // or set fixed expire age in seconds by doing like this
    // ttl: { estimateExpireAge: () => 60 * 60 * 24 * 365 }, // 1 year
  };
});

Here is t…

Replies: 2 comments 5 replies

Comment options

You must be logged in to vote
3 replies
@alex-guoba
Comment options

@better-salmon
Comment options

@alex-guoba
Comment options

Answer selected by alex-guoba
Comment options

You must be logged in to vote
2 replies
@alex-guoba
Comment options

@FanManutd
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #488 on April 24, 2024 08:52.