@@ -130,26 +130,26 @@ const makeHandler = (conf: NextConfig, app, pageRoot, staticManifest: Array<[str
130
130
131
131
// Sending SWR headers causes undefined behaviour with the Netlify CDN
132
132
const cacheHeader = multiValueHeaders [ 'cache-control' ] ?. [ 0 ]
133
+ const ttl = getMaxAge ( cacheHeader )
133
134
134
135
if ( cacheHeader ?. includes ( 'stale-while-revalidate' ) ) {
135
- if ( requestMode === 'odb' ) {
136
- const ttl = getMaxAge ( cacheHeader )
137
- // Long-expiry TTL is basically no TTL, so we'll skip it
138
- if ( ttl > 0 && ttl < ONE_YEAR_IN_SECONDS ) {
139
- // ODBs currently have a minimum TTL of 60 seconds
140
- result . ttl = Math . max ( ttl , 60 )
141
- }
142
- const ephemeralCodes = [ 301 , 302 , 307 , 308 , 404 ]
143
- if ( ttl === ONE_YEAR_IN_SECONDS && ephemeralCodes . includes ( result . statusCode ) ) {
144
- // Only cache for 60s if default TTL provided
145
- result . ttl = 60
146
- }
147
- if ( result . ttl > 0 ) {
148
- requestMode = `odb ttl=${ result . ttl } `
149
- }
136
+ // Long-expiry TTL is basically no TTL, so we'll skip it
137
+ if ( requestMode === 'odb' && ttl > 0 && ttl < ONE_YEAR_IN_SECONDS ) {
138
+ // ODBs currently have a minimum TTL of 60 seconds
139
+ result . ttl = Math . max ( ttl , 60 )
150
140
}
151
141
multiValueHeaders [ 'cache-control' ] = [ 'public, max-age=0, must-revalidate' ]
152
142
}
143
+
144
+ // We don't want to cache not found or redirects for ever
145
+ const ephemeralCodes = [ 301 , 302 , 307 , 308 , 404 ]
146
+ if ( ephemeralCodes . includes ( result . statusCode ) && requestMode === 'odb' && result . ttl === undefined ) {
147
+ result . ttl = 60
148
+ }
149
+
150
+ if ( result . ttl > 0 ) {
151
+ requestMode = `odb ttl=${ result . ttl } `
152
+ }
153
153
multiValueHeaders [ 'x-nf-render-mode' ] = [ requestMode ]
154
154
155
155
console . log ( `[${ event . httpMethod } ] ${ event . path } (${ requestMode ?. toUpperCase ( ) } )` )
0 commit comments