Skip to content

Commit

Permalink
fix: also use etag for private cache
Browse files Browse the repository at this point in the history
  • Loading branch information
codename-niels committed Aug 13, 2024
1 parent eeacc42 commit 4881784
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
12 changes: 6 additions & 6 deletions npm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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) {
Expand All @@ -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',
Expand Down
4 changes: 2 additions & 2 deletions npm/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion npm/package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down

0 comments on commit 4881784

Please sign in to comment.