@@ -384,6 +384,62 @@ public virtual async Task CanRemoveByPrefixAsync()
384384 }
385385 }
386386
387+ public virtual async Task CanRemoveByPrefixWithScopedCachesAsync ( )
388+ {
389+ var cache = GetCacheClient ( ) ;
390+ if ( cache == null )
391+ return ;
392+
393+ using ( cache )
394+ {
395+ await cache . RemoveAllAsync ( ) ;
396+ var scopedCache1 = new ScopedCacheClient ( cache , "scoped1" ) ;
397+
398+ const string cacheKey = "key" ;
399+ await cache . SetAsync ( cacheKey , 1 ) ;
400+ await scopedCache1 . SetAsync ( cacheKey , 1 ) ;
401+ Assert . Equal ( 1 , ( await cache . GetAsync < int > ( cacheKey ) ) . Value ) ;
402+ Assert . Equal ( 1 , ( await scopedCache1 . GetAsync < int > ( cacheKey ) ) . Value ) ;
403+
404+ // Remove by prefix should only remove the unscoped cache.
405+ Assert . Equal ( 1 , await cache . RemoveByPrefixAsync ( cacheKey ) ) ;
406+ Assert . False ( await cache . ExistsAsync ( cacheKey ) ) ;
407+ Assert . True ( await scopedCache1 . ExistsAsync ( cacheKey ) ) ;
408+ Assert . Equal ( 1 , ( await scopedCache1 . GetAsync < int > ( cacheKey ) ) . Value ) ;
409+
410+ // Add the unscoped cache value back.
411+ await cache . SetAsync ( cacheKey , 1 ) ;
412+
413+ // Remove by empty key.
414+ Assert . Equal ( 1 , await scopedCache1 . RemoveByPrefixAsync ( String . Empty ) ) ;
415+ Assert . True ( await cache . ExistsAsync ( cacheKey ) ) ;
416+ Assert . False ( await scopedCache1 . ExistsAsync ( cacheKey ) ) ;
417+
418+ // Add the scoped cache value back.
419+ await scopedCache1 . SetAsync ( cacheKey , 1 ) ;
420+
421+ Assert . Equal ( 2 , await cache . RemoveByPrefixAsync ( String . Empty ) ) ;
422+ Assert . False ( await cache . ExistsAsync ( cacheKey ) ) ;
423+ Assert . False ( await scopedCache1 . ExistsAsync ( cacheKey ) ) ;
424+
425+ // Reset client values
426+ await cache . SetAsync ( cacheKey , 1 ) ;
427+ await scopedCache1 . SetAsync ( cacheKey , 1 ) ;
428+
429+ // Remove by *.
430+ Assert . Equal ( 1 , await scopedCache1 . RemoveByPrefixAsync ( "*" ) ) ;
431+ Assert . True ( await cache . ExistsAsync ( cacheKey ) ) ;
432+ Assert . False ( await scopedCache1 . ExistsAsync ( cacheKey ) ) ;
433+
434+ // Reset client values
435+ await scopedCache1 . SetAsync ( cacheKey , 1 ) ;
436+
437+ Assert . Equal ( 2 , await cache . RemoveByPrefixAsync ( "*" ) ) ;
438+ Assert . False ( await cache . ExistsAsync ( cacheKey ) ) ;
439+ Assert . False ( await scopedCache1 . ExistsAsync ( cacheKey ) ) ;
440+ }
441+ }
442+
387443 public virtual async Task CanRemoveByPrefixMultipleEntriesAsync ( int count )
388444 {
389445 var cache = GetCacheClient ( ) ;
0 commit comments