GBPriceCache displays eviction statistics.
Some checks failed
Build .NET Project / build (push) Has been cancelled

This commit is contained in:
2026-03-11 19:27:40 -04:00
parent 84ec9b31a3
commit 946ef2ba54

View File

@@ -43,6 +43,8 @@ namespace MarketData.Cache
public class GBPriceCache : IDisposable
{
private static readonly int EVICTION_DAYCOUNT=252; // upon eviction trigger remove all data older than maxdate - evictionPolicyThreshholdDays
private Thread cacheMonitorThread = null;
private volatile bool threadRun = true;
private Object thisLock = new Object();
@@ -52,7 +54,7 @@ namespace MarketData.Cache
private DateGenerator dateGenerator = new DateGenerator();
private static GBPriceCache priceCacheInstance = null;
private int cacheRefreshAfter = 120000; // 2 minutes
private SemaphoreSlim fetchSemaphore = new SemaphoreSlim(8); // max 8 concurrent DB fetches
private SemaphoreSlim fetchSemaphore = new SemaphoreSlim(8); // max 8 concurrent DB fetches
public IPricingDataAccess PricingDataAccess { get; set; } = new RealPricingDA();
protected GBPriceCache()
@@ -330,9 +332,13 @@ namespace MarketData.Cache
DateTime maxDate = snapshot.PriceCache.Values.SelectMany(p => p.Keys).DefaultIfEmpty(DateTime.MinValue).Max();
if (maxDate != DateTime.MinValue)
{
DateTime evictBefore = dateGenerator.GenerateHistoricalDates(maxDate, 252).Min();
MDTrace.WriteLine(LogLevel.DEBUG, $"GBPriceCache, clearing cache on or before {evictBefore.ToShortDateString()}");
UpdateSnapshot(BuildEvictedPriceCache(evictBefore), new Dictionary<String, Price>(), new Dictionary<String, bool>());
DateTime evictBefore = dateGenerator.GenerateHistoricalDates(maxDate, EVICTION_DAYCOUNT).Min();
int beforeCount = snapshot.PriceCache.Values.Sum(p => p.Count);
Dictionary<String, PricesByDate> newCache = BuildEvictedPriceCache(evictBefore);
int afterCount = newCache.Values.Sum(p => p.Count);
int removed = beforeCount - afterCount;
MDTrace.WriteLine(LogLevel.DEBUG, $"GBPriceCache eviction: removed {removed} prices (before={beforeCount}, after={afterCount}) on or before {evictBefore.ToShortDateString()}");
UpdateSnapshot(newCache, new Dictionary<String, Price>(), new Dictionary<String, bool>());
GC.Collect();
}
}