Skip to content

Commit

Permalink
feat: added stale-white-revalidate directive
Browse files Browse the repository at this point in the history
  • Loading branch information
sametcodes committed Mar 21, 2024
1 parent e4f21ff commit ba7e946
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions middlewares/api/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,16 @@ export const setCacheControl = (
query: { cache_time, _vercel_no_cache },
} = res.locals;

res.setHeader("Cache-Control", "max-age=60");
res.setHeader("Cache-Control", "max-age=60, stale-while-revalidate=2592000");
if (_vercel_no_cache === undefined) {
res.setHeader("CDN-Cache-Control", `max-age=${cache_time}`);
res.setHeader("Vercel-CDN-Cache-Control", `max-age=${cache_time}`);
res.setHeader(
"CDN-Cache-Control",
`max-age=${cache_time}, stale-while-revalidate=2592000`
);
res.setHeader(
"Vercel-CDN-Cache-Control",
`max-age=${cache_time}, stale-while-revalidate=2592000`
);
}

next();
Expand Down

0 comments on commit ba7e946

Please sign in to comment.