@@ -372,6 +372,22 @@ describe('CacheHandler', () => {
372
372
expect ( mockLogger . info ) . toHaveBeenNthCalledWith ( 1 , `Revalidate by path ${ mockCacheKey } ` )
373
373
} )
374
374
375
+ it ( 'should revalidate multiple paths when passed as array' , async ( ) => {
376
+ Cache . setConfig ( {
377
+ logger : mockLogger ,
378
+ cache : new FileSystemCache ( )
379
+ } )
380
+ const cacheHandler = new Cache ( mockNextHandlerContext )
381
+ const paths = [ `${ NEXT_CACHE_IMPLICIT_TAG_ID } path1` , `${ NEXT_CACHE_IMPLICIT_TAG_ID } path2` ]
382
+
383
+ await cacheHandler . revalidateTag ( paths )
384
+
385
+ expect ( mockLogger . info ) . toHaveBeenCalledTimes ( 2 )
386
+ expect ( mockLogger . info ) . toHaveBeenNthCalledWith ( 1 , 'Revalidate by path path1' )
387
+ expect ( mockLogger . info ) . toHaveBeenNthCalledWith ( 2 , 'Revalidate by path path2' )
388
+ expect ( mockDeleteAllByKeyMatchData ) . toHaveBeenCalledTimes ( 2 )
389
+ } )
390
+
375
391
it ( 'should log when revalidate tag' , async ( ) => {
376
392
Cache . setConfig ( {
377
393
logger : mockLogger ,
@@ -385,6 +401,41 @@ describe('CacheHandler', () => {
385
401
expect ( mockLogger . info ) . toHaveBeenNthCalledWith ( 1 , `Revalidate by tag ${ mockCacheKey } ` )
386
402
} )
387
403
404
+ it ( 'should revalidate multiple tags when passed as array' , async ( ) => {
405
+ Cache . setConfig ( {
406
+ logger : mockLogger ,
407
+ cache : new FileSystemCache ( )
408
+ } )
409
+ const cacheHandler = new Cache ( mockNextHandlerContext )
410
+ const tags = [ 'tag1' , 'tag2' , 'tag3' ]
411
+
412
+ await cacheHandler . revalidateTag ( tags )
413
+
414
+ expect ( mockLogger . info ) . toHaveBeenCalledTimes ( 3 )
415
+ expect ( mockLogger . info ) . toHaveBeenNthCalledWith ( 1 , 'Revalidate by tag tag1' )
416
+ expect ( mockLogger . info ) . toHaveBeenNthCalledWith ( 2 , 'Revalidate by tag tag2' )
417
+ expect ( mockLogger . info ) . toHaveBeenNthCalledWith ( 3 , 'Revalidate by tag tag3' )
418
+ expect ( mockRevalidateTagData ) . toHaveBeenCalledTimes ( 3 )
419
+ } )
420
+
421
+ it ( 'should handle mixed array of paths and regular tags' , async ( ) => {
422
+ Cache . setConfig ( {
423
+ logger : mockLogger ,
424
+ cache : new FileSystemCache ( )
425
+ } )
426
+ const cacheHandler = new Cache ( mockNextHandlerContext )
427
+ const tags = [ `${ NEXT_CACHE_IMPLICIT_TAG_ID } path1` , 'regularTag' , `${ NEXT_CACHE_IMPLICIT_TAG_ID } path2` ]
428
+
429
+ await cacheHandler . revalidateTag ( tags )
430
+
431
+ expect ( mockLogger . info ) . toHaveBeenCalledTimes ( 3 )
432
+ expect ( mockLogger . info ) . toHaveBeenNthCalledWith ( 1 , 'Revalidate by path path1' )
433
+ expect ( mockLogger . info ) . toHaveBeenNthCalledWith ( 2 , 'Revalidate by tag regularTag' )
434
+ expect ( mockLogger . info ) . toHaveBeenNthCalledWith ( 3 , 'Revalidate by path path2' )
435
+ expect ( mockDeleteAllByKeyMatchData ) . toHaveBeenCalledTimes ( 2 )
436
+ expect ( mockRevalidateTagData ) . toHaveBeenCalledTimes ( 1 )
437
+ } )
438
+
388
439
it ( 'should log when failed to revalidate tag' , async ( ) => {
389
440
const errorMessage = 'error revalidate'
390
441
mockRevalidateTagData . mockRejectedValueOnce ( errorMessage )
@@ -404,6 +455,31 @@ describe('CacheHandler', () => {
404
455
expect ( mockLogger . error ) . toHaveBeenCalledWith ( `Failed revalidate by ${ mockCacheKey } ` , errorMessage )
405
456
} )
406
457
458
+ it ( 'should continue processing tags in array if one fails' , async ( ) => {
459
+ const errorMessage = 'error revalidate'
460
+ mockRevalidateTagData . mockRejectedValueOnce ( errorMessage )
461
+
462
+ Cache . setConfig ( {
463
+ logger : mockLogger ,
464
+ cache : new FileSystemCache ( )
465
+ } )
466
+ const cacheHandler = new Cache ( mockNextHandlerContext )
467
+ const tags = [ 'tag1' , 'tag2' , 'tag3' ]
468
+
469
+ await cacheHandler . revalidateTag ( tags )
470
+
471
+ expect ( mockLogger . info ) . toHaveBeenCalledTimes ( 3 )
472
+ expect ( mockLogger . info ) . toHaveBeenNthCalledWith ( 1 , 'Revalidate by tag tag1' )
473
+ expect ( mockLogger . info ) . toHaveBeenNthCalledWith ( 2 , 'Revalidate by tag tag2' )
474
+ expect ( mockLogger . info ) . toHaveBeenNthCalledWith ( 3 , 'Revalidate by tag tag3' )
475
+
476
+ expect ( mockLogger . error ) . toHaveBeenCalledTimes ( 1 )
477
+ expect ( mockLogger . error ) . toHaveBeenCalledWith ( 'Failed revalidate by tag1' , errorMessage )
478
+
479
+ // Should continue with other tags despite the error
480
+ expect ( mockRevalidateTagData ) . toHaveBeenCalledTimes ( 3 )
481
+ } )
482
+
407
483
it ( 'should log when failed to revalidate path' , async ( ) => {
408
484
const errorMessage = 'error revalidate'
409
485
mockDeleteAllByKeyMatchData . mockRejectedValueOnce ( errorMessage )
0 commit comments