@@ -27,22 +27,22 @@ import (
2727func TestGetCacheReturnsSameCacheForSameConfig (t * testing.T ) {
2828 ctx := context .Background ()
2929 cacheManager := NewCacheManager (ctx , true )
30- cache0 , _ := cacheManager .GetCache (ctx , "cacheA" , 85 , time .Second , true )
31- cache1 , _ := cacheManager .GetCache (ctx , "cacheA" , 85 , time .Second , true )
30+ cache0 , _ := cacheManager .GetCache (ctx , "ns1" , " cacheA" , 85 , time .Second , true )
31+ cache1 , _ := cacheManager .GetCache (ctx , "ns1" , " cacheA" , 85 , time .Second , true )
3232
3333 assert .Equal (t , cache0 , cache1 )
34- assert .Equal (t , []string {"cacheA" }, cacheManager .ListCacheNames ())
34+ assert .Equal (t , []string {"ns1: cacheA" }, cacheManager .ListCacheNames ("ns1" ))
3535
36- cache2 , _ := cacheManager .GetCache (ctx , "cacheB" , 85 , time .Second , true )
36+ cache2 , _ := cacheManager .GetCache (ctx , "ns1" , " cacheB" , 85 , time .Second , true )
3737 assert .NotEqual (t , cache0 , cache2 )
38- assert .Equal (t , 2 , len (cacheManager .ListCacheNames ()))
38+ assert .Equal (t , 2 , len (cacheManager .ListCacheNames ("ns1" )))
3939}
4040
4141func TestTwoSeparateCacheWorksIndependently (t * testing.T ) {
4242 ctx := context .Background ()
4343 cacheManager := NewCacheManager (ctx , true )
44- cache0 , _ := cacheManager .GetCache (ctx , "cacheA" , 85 , time .Second , true )
45- cache1 , _ := cacheManager .GetCache (ctx , "cacheB" , 85 , time .Second , true )
44+ cache0 , _ := cacheManager .GetCache (ctx , "ns1" , " cacheA" , 85 , time .Second , true )
45+ cache1 , _ := cacheManager .GetCache (ctx , "ns1" , " cacheB" , 85 , time .Second , true )
4646
4747 cache0 .SetInt ("int0" , 100 )
4848 assert .Equal (t , 100 , cache0 .GetInt ("int0" ))
@@ -66,29 +66,29 @@ func TestCacheEnablement(t *testing.T) {
6666 var zero int64 = 0
6767 // test global enablement set to false
6868 disabledCacheManager := NewCacheManager (ctx , false )
69- cache0 , _ := disabledCacheManager .GetCache (ctx , "cache0" , 85 , time .Second , false )
69+ cache0 , _ := disabledCacheManager .GetCache (ctx , "ns1" , " cache0" , 85 , time .Second , false )
7070 assert .Equal (t , false , cache0 .IsEnabled ())
7171
7272 cache0 .SetInt64 ("int0" , hundred )
7373 assert .Equal (t , nil , cache0 .Get ("int0" ))
7474
7575 // check individual cache cannot be turned on when the cache manager is disabled
76- cache1 , _ := disabledCacheManager .GetCache (ctx , "cache1" , 85 , time .Second , true )
76+ cache1 , _ := disabledCacheManager .GetCache (ctx , "ns1" , " cache1" , 85 , time .Second , true )
7777 assert .Equal (t , false , cache1 .IsEnabled ())
7878
7979 // test global enablement set to true
8080
8181 enabledCacheManager := NewCacheManager (ctx , true )
8282 // check individual cache can be turned off when the cache manager is enabled
83- cache0 , _ = enabledCacheManager .GetCache (ctx , "cache0" , 85 , time .Second , false )
83+ cache0 , _ = enabledCacheManager .GetCache (ctx , "ns1" , " cache0" , 85 , time .Second , false )
8484 assert .Equal (t , false , cache0 .IsEnabled ())
8585
8686 cache0 .SetInt64 ("int0" , hundred )
8787 assert .Equal (t , zero , cache0 .GetInt64 ("int0" ))
8888 deleted := cache0 .Delete ("int0" )
8989 assert .False (t , deleted )
9090
91- cache1 , _ = enabledCacheManager .GetCache (ctx , "cache1" , 85 , time .Second , true )
91+ cache1 , _ = enabledCacheManager .GetCache (ctx , "ns1" , " cache1" , 85 , time .Second , true )
9292 assert .Equal (t , true , cache1 .IsEnabled ())
9393
9494 cache1 .SetInt64 ("int0" , hundred )
@@ -101,3 +101,28 @@ func TestUmmanagedCacheInstance(t *testing.T) {
101101 uc1 := NewUmanagedCache (context .Background (), 100 , 5 * time .Minute )
102102 assert .NotEqual (t , uc0 , uc1 )
103103}
104+
105+ func TestResetCachesForNamespace (t * testing.T ) {
106+ ctx := context .Background ()
107+ cacheManager := NewCacheManager (ctx , true )
108+ cacheNS1 , _ := cacheManager .GetCache (ctx , "ns1" , "cache1" , 85 , time .Second , true )
109+ cacheNS1 .Set ("key1" , "value1" )
110+
111+ cacheNS2 , _ := cacheManager .GetCache (ctx , "ns2" , "cache1" , 85 , time .Second , true )
112+ cacheNS2 .Set ("key2" , "value2" )
113+
114+ cacheNS1_a , _ := cacheManager .GetCache (ctx , "ns1" , "cache1" , 85 , time .Second , true )
115+ assert .Equal (t , cacheNS1 , cacheNS1_a )
116+ assert .Equal (t , "value1" , cacheNS1_a .Get ("key1" ))
117+
118+ cacheManager .ResetCaches ("ns1" )
119+
120+ cacheNS2_a , _ := cacheManager .GetCache (ctx , "ns2" , "cache1" , 85 , time .Second , true )
121+ assert .Equal (t , cacheNS2 , cacheNS2_a )
122+ assert .Equal (t , "value2" , cacheNS2_a .Get ("key2" ))
123+
124+ cacheNS1_b , _ := cacheManager .GetCache (ctx , "ns1" , "cache1" , 85 , time .Second , true )
125+ assert .NotEqual (t , cacheNS1 , cacheNS1_b )
126+ assert .Nil (t , cacheNS1_b .Get ("key1" ))
127+
128+ }
0 commit comments