public override string ToString() { StringBuilder builder = new StringBuilder(GetType().Name); builder.AppendLine(); builder.Append("\tMaxActive: "); builder.AppendLine(Interlocked.Read(ref _maxActive).ToString()); builder.Append("\tActive: "); builder.AppendLine(Interlocked.Read(ref _activeCount).ToString()); var requestCount = RequestCount; var requestCompleteCount = RequestCompleteCount; var requestFailed = RequestFailed; var tickCount = Interlocked.Read(ref _tickCount); builder.Append("\tRequestCount: "); builder.AppendLine(RequestCount.ToString()); builder.Append("\tRequestFailed: "); builder.AppendLine(RequestFailed.ToString()); builder.Append("\tRequestComplete: "); builder.AppendLine(Interlocked.Read(ref requestCompleteCount).ToString()); if (requestCount > 0) { TimeSpan timeSpan = TimeSpan.FromTicks(tickCount); var avg = timeSpan.TotalMilliseconds / (double)requestCount; builder.Append("\tAvgTimeToLastByte: "); builder.AppendLine(avg.ToString("0.0000000")); } builder.AppendLine("\tCache:"); foreach (var item in Cache.Keys) { builder.Append("\t\t"); builder.Append(item); builder.Append("="); builder.AppendLine(Cache[item].TokenSource.IsCancellationRequested ? "complete" : "building"); } return(builder.ToString()); }
public void SaveStats() { File.WriteAllLines("./cache-stats", new string[] { RequestCount.ToString(), HitCount.ToString() }); }