@@ -121,11 +121,19 @@ export class NetlifyCacheHandler implements CacheHandlerForMultipleVersions {
121121 }
122122
123123 private captureCacheTags ( cacheValue : NetlifyIncrementalCacheValue | null , key : string ) {
124+ const requestContext = getRequestContext ( )
125+
124126 if ( ! cacheValue ) {
127+ if ( requestContext ?. responseCacheTags ) {
128+ const cacheTags = [ `_N_T_${ key === '/index' ? '/' : encodeURI ( key ) } ` ]
129+ requestContext . responseCacheTags = cacheTags
130+
131+ console . log ( 'cache tags set:' , cacheTags )
132+ }
133+
125134 return
126135 }
127136
128- const requestContext = getRequestContext ( )
129137 // Bail if we can't get request context
130138 if ( ! requestContext ) {
131139 return
@@ -393,28 +401,28 @@ export class NetlifyCacheHandler implements CacheHandlerForMultipleVersions {
393401
394402 await this . cacheStore . set ( key , { lastModified, value } , 'blobStore.set' )
395403
396- if ( data ?. kind === 'PAGE' || data ?. kind === 'PAGES' ) {
397- const requestContext = getRequestContext ( )
398- if ( requestContext ?. didPagesRouterOnDemandRevalidate ) {
399- // encode here to deal with non ASCII characters in the key
400- const tag = `_N_T_${ key === '/index' ? '/' : encodeURI ( key ) } `
401- const tags = tag . split ( / , | % 2 c / gi) . filter ( Boolean )
402-
403- if ( tags . length === 0 ) {
404- return
405- }
404+ // if (data?.kind === 'PAGE' || data?.kind === 'PAGES') {
405+ const requestContext = getRequestContext ( )
406+ if ( requestContext ?. didPagesRouterOnDemandRevalidate ) {
407+ // encode here to deal with non ASCII characters in the key
408+ const tag = `_N_T_${ key === '/index' ? '/' : encodeURI ( key ) } `
409+ const tags = tag . split ( / , | % 2 c / gi) . filter ( Boolean )
406410
407- getLogger ( ) . debug ( `Purging CDN cache for: [${ tag } ]` )
408- requestContext . trackBackgroundWork (
409- purgeCache ( { tags, userAgent : purgeCacheUserAgent } ) . catch ( ( error ) => {
410- // TODO: add reporting here
411- getLogger ( )
412- . withError ( error )
413- . error ( `[NetlifyCacheHandler]: Purging the cache for tag ${ tag } failed` )
414- } ) ,
415- )
411+ if ( tags . length === 0 ) {
412+ return
416413 }
414+
415+ getLogger ( ) . debug ( `Purging CDN cache for: [${ tag } ]` )
416+ requestContext . trackBackgroundWork (
417+ purgeCache ( { tags, userAgent : purgeCacheUserAgent } ) . catch ( ( error ) => {
418+ // TODO: add reporting here
419+ getLogger ( )
420+ . withError ( error )
421+ . error ( `[NetlifyCacheHandler]: Purging the cache for tag ${ tag } failed` )
422+ } ) ,
423+ )
417424 }
425+ // }
418426 } )
419427 }
420428
0 commit comments