@@ -244,19 +244,33 @@ export class NetlifyCacheHandler implements CacheHandler {
244
244
if ( requestContext ?. didPagesRouterOnDemandRevalidate ) {
245
245
const tag = `_N_T_${ key === '/index' ? '/' : key } `
246
246
getLogger ( ) . debug ( `Purging CDN cache for: [${ tag } ]` )
247
- purgeCache ( { tags : [ tag ] } ) . catch ( ( error ) => {
248
- // TODO: add reporting here
249
- getLogger ( )
250
- . withError ( error )
251
- . error ( `[NetlifyCacheHandler]: Purging the cache for tag ${ tag } failed` )
252
- } )
247
+ requestContext . trackBackgroundWork (
248
+ purgeCache ( { tags : [ tag ] } ) . catch ( ( error ) => {
249
+ // TODO: add reporting here
250
+ getLogger ( )
251
+ . withError ( error )
252
+ . error ( `[NetlifyCacheHandler]: Purging the cache for tag ${ tag } failed` )
253
+ } ) ,
254
+ )
253
255
}
254
256
}
255
257
} )
256
258
}
257
259
258
260
// eslint-disable-next-line @typescript-eslint/no-explicit-any
259
261
async revalidateTag ( tagOrTags : string | string [ ] , ...args : any ) {
262
+ const revalidateTagPromise = this . doRevalidateTag ( tagOrTags , ...args )
263
+
264
+ const requestContext = getRequestContext ( )
265
+ if ( requestContext ) {
266
+ requestContext . trackBackgroundWork ( revalidateTagPromise )
267
+ }
268
+
269
+ return revalidateTagPromise
270
+ }
271
+
272
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
273
+ private async doRevalidateTag ( tagOrTags : string | string [ ] , ...args : any ) {
260
274
getLogger ( ) . withFields ( { tagOrTags, args } ) . debug ( 'NetlifyCacheHandler.revalidateTag' )
261
275
262
276
const tags = Array . isArray ( tagOrTags ) ? tagOrTags : [ tagOrTags ]
@@ -275,7 +289,7 @@ export class NetlifyCacheHandler implements CacheHandler {
275
289
} ) ,
276
290
)
277
291
278
- purgeCache ( { tags } ) . catch ( ( error ) => {
292
+ await purgeCache ( { tags } ) . catch ( ( error ) => {
279
293
// TODO: add reporting here
280
294
getLogger ( )
281
295
. withError ( error )
0 commit comments