Skip to content

Commit 20e8826

Browse files
committed
fix: isr cache key got me dizzy
1 parent 277b6a0 commit 20e8826

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

app/composables/useVersionDistribution.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export function useVersionDistribution(packageName: MaybeRefOrGetter<string>) {
5151
filterOldVersions: showOldVersions.value ? 'false' : 'true',
5252
filterThreshold: showLowUsageVersions.value ? '0' : '1',
5353
},
54+
cache: 'default', // Don't force-cache since query params change frequently
5455
},
5556
)
5657

nuxt.config.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,13 @@ export default defineNuxtConfig({
9595
allowQuery: ['color', 'labelColor', 'label', 'name'],
9696
},
9797
},
98+
'/api/registry/downloads/**': {
99+
isr: {
100+
expiration: 60 * 60 /* one hour */,
101+
passQuery: true,
102+
allowQuery: ['mode', 'filterOldVersions', 'filterThreshold'],
103+
},
104+
},
98105
'/api/registry/docs/**': { isr: true, cache: { maxAge: 365 * 24 * 60 * 60 } },
99106
'/api/registry/file/**': { isr: true, cache: { maxAge: 365 * 24 * 60 * 60 } },
100107
'/api/registry/provenance/**': { isr: true, cache: { maxAge: 365 * 24 * 60 * 60 } },

server/api/registry/downloads/[...slug].get.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getQuery, setHeader } from 'h3'
1+
import { getQuery } from 'h3'
22
import * as v from 'valibot'
33
import { hash } from 'ohash'
44
import type { VersionDistributionResponse } from '#shared/types'
@@ -106,14 +106,6 @@ export default defineCachedEventHandler(
106106
timestamp: new Date().toISOString(),
107107
}
108108

109-
// Set cache headers for both client and CDN/edge caching
110-
// s-maxage controls shared cache (Vercel edge) behavior
111-
setHeader(
112-
event,
113-
'Cache-Control',
114-
`public, max-age=${CACHE_MAX_AGE_ONE_HOUR}, s-maxage=${CACHE_MAX_AGE_ONE_HOUR}`,
115-
)
116-
117109
if (filterOldVersionsBool) {
118110
try {
119111
const oneYearAgo = new Date()
@@ -154,7 +146,7 @@ export default defineCachedEventHandler(
154146
const query = getQuery(event)
155147
// Use ohash to create deterministic cache key from query params
156148
// This ensures different param combinations = different cache entries
157-
return `version-downloads:v4:${slug}:${hash(query)}`
149+
return `version-downloads:v5:${slug}:${hash(query)}`
158150
},
159151
},
160152
)

0 commit comments

Comments
 (0)