From ba7e94690ae5b1c3788ec17a6b658f657f34c94b Mon Sep 17 00:00:00 2001 From: Samet Date: Fri, 22 Mar 2024 00:26:49 +0300 Subject: [PATCH] feat: added stale-white-revalidate directive --- middlewares/api/cache.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/middlewares/api/cache.ts b/middlewares/api/cache.ts index 6e47f0a..f2b3ce4 100644 --- a/middlewares/api/cache.ts +++ b/middlewares/api/cache.ts @@ -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();