@@ -283,19 +283,33 @@ export class NetlifyCacheHandler implements CacheHandler {
283
283
if ( requestContext ?. didPagesRouterOnDemandRevalidate ) {
284
284
const tag = `_N_T_${ key === '/index' ? '/' : key } `
285
285
getLogger ( ) . debug ( `Purging CDN cache for: [${ tag } ]` )
286
- purgeCache ( { tags : [ tag ] } ) . catch ( ( error ) => {
287
- // TODO: add reporting here
288
- getLogger ( )
289
- . withError ( error )
290
- . error ( `[NetlifyCacheHandler]: Purging the cache for tag ${ tag } failed` )
291
- } )
286
+ requestContext . trackBackgroundWork (
287
+ purgeCache ( { tags : [ tag ] } ) . catch ( ( error ) => {
288
+ // TODO: add reporting here
289
+ getLogger ( )
290
+ . withError ( error )
291
+ . error ( `[NetlifyCacheHandler]: Purging the cache for tag ${ tag } failed` )
292
+ } ) ,
293
+ )
292
294
}
293
295
}
294
296
} )
295
297
}
296
298
297
299
// eslint-disable-next-line @typescript-eslint/no-explicit-any
298
300
async revalidateTag ( tagOrTags : string | string [ ] , ...args : any ) {
301
+ const revalidateTagPromise = this . doRevalidateTag ( tagOrTags , ...args )
302
+
303
+ const requestContext = getRequestContext ( )
304
+ if ( requestContext ) {
305
+ requestContext . trackBackgroundWork ( revalidateTagPromise )
306
+ }
307
+
308
+ return revalidateTagPromise
309
+ }
310
+
311
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
312
+ private async doRevalidateTag ( tagOrTags : string | string [ ] , ...args : any ) {
299
313
getLogger ( ) . withFields ( { tagOrTags, args } ) . debug ( 'NetlifyCacheHandler.revalidateTag' )
300
314
301
315
const tags = Array . isArray ( tagOrTags ) ? tagOrTags : [ tagOrTags ]
@@ -314,7 +328,7 @@ export class NetlifyCacheHandler implements CacheHandler {
314
328
} ) ,
315
329
)
316
330
317
- purgeCache ( { tags } ) . catch ( ( error ) => {
331
+ await purgeCache ( { tags } ) . catch ( ( error ) => {
318
332
// TODO: add reporting here
319
333
getLogger ( )
320
334
. withError ( error )
0 commit comments