From 488178406648a560e5292d21075362ac76a3a294 Mon Sep 17 00:00:00 2001 From: Niels Date: Tue, 13 Aug 2024 13:01:10 +0200 Subject: [PATCH] fix: also use etag for private cache --- npm/index.ts | 12 ++++++------ npm/package-lock.json | 4 ++-- npm/package.json | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/npm/index.ts b/npm/index.ts index e297ecd..ce2acc7 100644 --- a/npm/index.ts +++ b/npm/index.ts @@ -24,7 +24,7 @@ const DEFAULT_HEADER_OPTIONS: HeaderOptions = { mustRevalidate: false, maxAge: 60, sMaxAge: null, - public: true, + public: false, private: false, noCache: false, etagCacheKey: 'cache-control-etag', @@ -78,10 +78,7 @@ export async function createCacheControlResponse( (param) => !new URL(request.url).searchParams.has(param) ) ) { - const allowPublicCaching = - options.public && !request.headers.has('Authorization'); - - if (allowPublicCaching && options.etagCacheKey && redis) { + if (options.etagCacheKey && redis) { const etag = await redis.get(options.etagCacheKey); if (etag) { @@ -98,8 +95,11 @@ export async function createCacheControlResponse( } headers['Cache-Control'] = [ + options.public && + !request.headers.has('Authorization') && + !options.private && + 'public', options.private && !options.public && 'private', - allowPublicCaching && !options.private && 'public', options.maxAge !== null && `max-age=${options.maxAge}`, options.sMaxAge !== null && `s-maxage=${options.sMaxAge}`, options.mustRevalidate && 'must-revalidate', diff --git a/npm/package-lock.json b/npm/package-lock.json index ca510d6..425d937 100644 --- a/npm/package-lock.json +++ b/npm/package-lock.json @@ -1,12 +1,12 @@ { "name": "@born05/sveltekit-cache-control", - "version": "1.2.4", + "version": "1.2.5", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@born05/sveltekit-cache-control", - "version": "1.2.4", + "version": "1.2.5", "license": "ISC", "dependencies": { "ioredis": "^5.3.2" diff --git a/npm/package.json b/npm/package.json index f19a00e..60f8df8 100644 --- a/npm/package.json +++ b/npm/package.json @@ -1,6 +1,6 @@ { "name": "@born05/sveltekit-cache-control", - "version": "1.2.4", + "version": "1.2.5", "description": "A simple way to add control caching in your SvelteKit project.", "main": "index.js", "scripts": {