@@ -1300,11 +1300,14 @@ public class ConcurrentLruIntegrityChecker<K, V, I, P, T>
13001300 where T : struct , ITelemetryPolicy < K , V >
13011301 {
13021302 private readonly ConcurrentLruCore < K , V , I , P , T > cache ;
1303-
1303+
1304+ private readonly ConcurrentDictionary < K , I > dictionary ;
13041305 private readonly ConcurrentQueue < I > hotQueue ;
13051306 private readonly ConcurrentQueue < I > warmQueue ;
13061307 private readonly ConcurrentQueue < I > coldQueue ;
13071308
1309+ private static FieldInfo dictionaryField = typeof ( ConcurrentLruCore < K , V , I , P , T > ) . GetField ( "dictionary" , BindingFlags . NonPublic | BindingFlags . Instance ) ;
1310+
13081311 private static FieldInfo hotQueueField = typeof ( ConcurrentLruCore < K , V , I , P , T > ) . GetField ( "hotQueue" , BindingFlags . NonPublic | BindingFlags . Instance ) ;
13091312 private static FieldInfo warmQueueField = typeof ( ConcurrentLruCore < K , V , I , P , T > ) . GetField ( "warmQueue" , BindingFlags . NonPublic | BindingFlags . Instance ) ;
13101313 private static FieldInfo coldQueueField = typeof ( ConcurrentLruCore < K , V , I , P , T > ) . GetField ( "coldQueue" , BindingFlags . NonPublic | BindingFlags . Instance ) ;
@@ -1314,6 +1317,7 @@ public ConcurrentLruIntegrityChecker(ConcurrentLruCore<K, V, I, P, T> cache)
13141317 this . cache = cache ;
13151318
13161319 // get queues via reflection
1320+ this . dictionary = ( ConcurrentDictionary < K , I > ) dictionaryField . GetValue ( cache ) ;
13171321 this . hotQueue = ( ConcurrentQueue < I > ) hotQueueField . GetValue ( cache ) ;
13181322 this . warmQueue = ( ConcurrentQueue < I > ) warmQueueField . GetValue ( cache ) ;
13191323 this . coldQueue = ( ConcurrentQueue < I > ) coldQueueField . GetValue ( cache ) ;
@@ -1344,7 +1348,7 @@ private void ValidateQueue(ConcurrentLruCore<K, V, I, P, T> cache, ConcurrentQue
13441348 // It is possible for the queues to contain 2 (or more) instances of the same key/item. One that was removed,
13451349 // and one that was added after the other was removed.
13461350 // In this case, the dictionary may contain the value only if the queues contain an entry for that key marked as WasRemoved == false.
1347- if ( cache . TryGet ( item . Key , out var value ) )
1351+ if ( dictionary . TryGetValue ( item . Key , out var value ) )
13481352 {
13491353 hotQueue . Union ( warmQueue ) . Union ( coldQueue )
13501354 . Any ( i => i . Key . Equals ( item . Key ) && ! i . WasRemoved )
@@ -1353,7 +1357,7 @@ private void ValidateQueue(ConcurrentLruCore<K, V, I, P, T> cache, ConcurrentQue
13531357 }
13541358 else
13551359 {
1356- cache . TryGet ( item . Key , out var value ) . Should ( ) . BeTrue ( $ "{ queueName } item { item . Key } was not present") ;
1360+ dictionary . TryGetValue ( item . Key , out var value ) . Should ( ) . BeTrue ( $ "{ queueName } item { item . Key } was not present") ;
13571361 }
13581362 }
13591363 }
0 commit comments