@@ -31,6 +31,8 @@ namespace BitFaster.Caching.Lfu
3131 /// Based on Caffeine written by Ben Manes.
3232 /// https://www.apache.org/licenses/LICENSE-2.0
3333 /// </remarks>
34+ [ DebuggerTypeProxy ( typeof ( ConcurrentLfu < , > . LfuDebugView ) ) ]
35+ [ DebuggerDisplay ( "Count = {Count}/{Capacity}" ) ]
3436 public sealed class ConcurrentLfu < K , V > : ICache < K , V > , IAsyncCache < K , V > , IBoundedPolicy
3537 {
3638 private const int MaxWriteBufferRetries = 100 ;
@@ -644,7 +646,7 @@ private void ReFitProtected()
644646 }
645647 }
646648
647- [ DebuggerDisplay ( "{Format()}" ) ]
649+ [ DebuggerDisplay ( "{Format(),nq }" ) ]
648650 private class DrainStatus
649651 {
650652 public const int Idle = 0 ;
@@ -687,7 +689,7 @@ public int Status()
687689 }
688690
689691 [ ExcludeFromCodeCoverage ]
690- private string Format ( )
692+ internal string Format ( )
691693 {
692694 switch ( this . drainStatus . Value )
693695 {
@@ -705,7 +707,8 @@ private string Format()
705707 }
706708 }
707709
708- private class CacheMetrics : ICacheMetrics
710+ [ DebuggerDisplay ( "Hit = {Hits}, Miss = {Misses}, Upd = {Updated}, Evict = {Evicted}" ) ]
711+ internal class CacheMetrics : ICacheMetrics
709712 {
710713 public long requestHitCount ;
711714 public long requestMissCount ;
@@ -741,6 +744,40 @@ public string FormatLruString()
741744 return sb . ToString ( ) ;
742745 }
743746#endif
747+
748+ [ ExcludeFromCodeCoverage ]
749+ internal class LfuDebugView
750+ {
751+ private ConcurrentLfu < K , V > lfu ;
752+
753+ public LfuDebugView ( ConcurrentLfu < K , V > lfu )
754+ {
755+ this . lfu = lfu ;
756+ }
757+
758+ public string Maintenance => lfu . drainStatus . Format ( ) ;
759+
760+ public ICacheMetrics Metrics => lfu . metrics ;
761+
762+ public StripedMpscBuffer < LfuNode < K , V > > ReadBuffer => this . lfu . readBuffer ;
763+
764+ public StripedMpscBuffer < LfuNode < K , V > > WriteBuffer => this . lfu . writeBuffer ;
765+
766+ public KeyValuePair < K , V > [ ] Items
767+ {
768+ get
769+ {
770+ var items = new KeyValuePair < K , V > [ lfu . Count ] ;
771+
772+ int index = 0 ;
773+ foreach ( var kvp in lfu )
774+ {
775+ items [ index ++ ] = kvp ;
776+ }
777+ return items ;
778+ }
779+ }
780+ }
744781 }
745782
746783 // Explicit layout cannot be a generic class member
0 commit comments