src/Microsoft.IdentityModel.Tokens/EventBasedLRUCache.cs
/// <summary>
/// Remove items from the Dictionary by the desired compaction percentage.
/// Since _map does not have LRU order, items are simply removed from using FirstOrDefault(). 
/// </summary>
Remove items from the Dictionary by the desired compaction percentage.
Since _map does not have LRU order, items are simply removed from using FirstOrDefault().
Remove items from the Dictionary by the desired compaction percentage . Since _map does not have LRU order items are simply removed from using FirstOrDefault () .
private void Compact()
        {
            var newCacheSize = CalculateNewCacheSize();
            while (_map.Count > newCacheSize)
            {
                var item = _map.FirstOrDefault();
                if (!item.Equals(default))
                {
                    if (_map.TryRemove(item.Key, out var cacheItem))
                        OnItemRemoved?.Invoke(cacheItem.Value);
                }
            }
        }
private void Compact ( ) { var newCacheSize = CalculateNewCacheSize ( ) ; while ( _map . Count > newCacheSize ) { var item = _map . FirstOrDefault ( ) ; if ( ! item . Equals ( default ) ) { if ( _map . TryRemove ( item . Key , out var cacheItem ) ) OnItemRemoved ? . Invoke ( cacheItem . Value ) ; } } }
Remove items from the Dictionary by the desired compaction percentage.
Remove items from the Dictionary by the desired compaction percentage .
// Since all items could have been removed by the public TryRemove() method, leaving the map empty, we need to check if a default value is returned. // Remove the item from the map only if the returned item is NOT default value.