Skip to content

fix: improved cdn cache hooks for dynamic 404 pages #2786

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Apr 2, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
chore: run format:fix
  • Loading branch information
mrstork committed Apr 1, 2025
commit cf47c741d27f84c64542ab0829a9b481c6b21a0a
6 changes: 5 additions & 1 deletion src/run/handlers/cache.cts
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,11 @@ export class NetlifyCacheHandler implements CacheHandlerForMultipleVersions {
return null
}

const staleByTags = await this.checkCacheEntryStaleByTags(blob, context.tags, context.softTags)
const staleByTags = await this.checkCacheEntryStaleByTags(
blob,
context.tags,
context.softTags,
)

if (staleByTags) {
span.addEvent('Stale', { staleByTags, key, ttl })
Expand Down
5 changes: 1 addition & 4 deletions src/run/headers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,10 +274,7 @@ export const setCacheControlHeaders = (
}
}

export const setCacheTagsHeaders = (
headers: Headers,
requestContext: RequestContext,
) => {
export const setCacheTagsHeaders = (headers: Headers, requestContext: RequestContext) => {
if (!headers.has('cache-control') && !headers.has('netlify-cdn-cache-control')) {
return
}
Expand Down
6 changes: 3 additions & 3 deletions tests/e2e/dynamic-cms.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ test.describe('Dynamic CMS', () => {
)
expect(headers1['netlify-cache-tag']).toEqual('_n_t_/content/blog')
expect(headers1['netlify-cdn-cache-control']).toMatch(
/s-maxage=31536000,( stale-while-revalidate=31536000,)? durable/
/s-maxage=31536000,( stale-while-revalidate=31536000,)? durable/,
)

// 2. Publish the blob, revalidate the dynamic page, and wait to regenerate
Expand All @@ -33,7 +33,7 @@ test.describe('Dynamic CMS', () => {
)
expect(headers2['netlify-cache-tag']).toEqual('_n_t_/content/blog')
expect(headers2['netlify-cdn-cache-control']).toMatch(
/s-maxage=31536000,( stale-while-revalidate=31536000,)? durable/
/s-maxage=31536000,( stale-while-revalidate=31536000,)? durable/,
)

// 4. Unpublish the blob, revalidate the dynamic page, and wait to regenerate
Expand All @@ -52,7 +52,7 @@ test.describe('Dynamic CMS', () => {
)
expect(headers3['netlify-cache-tag']).toEqual('_n_t_/content/blog')
expect(headers3['netlify-cdn-cache-control']).toMatch(
/s-maxage=31536000,( stale-while-revalidate=31536000,)? durable/
/s-maxage=31536000,( stale-while-revalidate=31536000,)? durable/,
)
})
})
Loading