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(); diff --git a/pages/api/view/[id].ts b/pages/api/view/[id].ts index da66174..97fff7b 100644 --- a/pages/api/view/[id].ts +++ b/pages/api/view/[id].ts @@ -9,7 +9,7 @@ import { } from "@/middlewares/api/private"; import { validateAccessToken, loadPassport } from "@/middlewares/api/auth"; import { resolveHandler } from "@/middlewares/api"; -// import { setCacheControl } from "@/middlewares/api/cache"; +import { setCacheControl } from "@/middlewares/api/cache"; import { NextApiRequest, NextApiResponse } from "next"; export default nextConnect() @@ -19,7 +19,7 @@ export default nextConnect() .use(resolveHandler) .use(loadPassport) .use(validateAccessToken) - // .use(setCacheControl) + .use(setCacheControl) .get((req: NextApiRequest, res: NextApiResponse) => { const { services, templates, connection, query, config } = res.locals; return handlePlatformAPI(