From a694727ca2f08c6014752fea69e13d4929cbb2e3 Mon Sep 17 00:00:00 2001 From: Niko Sams Date: Tue, 10 Oct 2023 10:30:11 +0200 Subject: [PATCH] Support s-maxage cache-control value --- src/cache.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cache.ts b/src/cache.ts index 62d2418..a719508 100644 --- a/src/cache.ts +++ b/src/cache.ts @@ -28,7 +28,7 @@ export function parseMeta(res: Response): CacheMeta | null { if (!cacheControl) { return null; } - const maxAgeMatch = cacheControl.match(/max-age=(\d+)/); + const maxAgeMatch = cacheControl.match(/(max-age|s-maxage)=(\d+)/); if (!maxAgeMatch) { return null; } @@ -36,7 +36,7 @@ export function parseMeta(res: Response): CacheMeta | null { const status = res.status; const headers = convertHeadersToObject(res.headers); - const maxAge = parseInt(maxAgeMatch[1], 10) * 1000; + const maxAge = parseInt(maxAgeMatch[2], 10) * 1000; const staleWhileRevalidateMatch = cacheControl.match(/stale-while-revalidate=(\d+)/); if (!staleWhileRevalidateMatch) { return { maxAge, headers, status };