Cache Monitoring & Diagnostics
CacheExpose exposes a full diagnostics surface — typed snapshots, several pre-formatted report strings, a structured monitoring dictionary for dashboards, health alerts, and manual cache management methods.
Structured snapshots
Three typed objects describe the cache state at a moment in time:
| Method | Returns | Use for |
|---|---|---|
GetCacheStatistics() | CacheStatistics | Per-store entry counts, LRU / LFU tracking-record counts, and estimated memory. |
GetCacheConfiguration() | CacheConfiguration | The currently active CacheOptions values. |
GetMemoryUsage() | CacheMemoryUsage | Estimated memory per store — CacheCalculator sizes live entries from fixed constants rather than measuring the GC. |
Report generators
Four pre-formatted text reports for logs, debugger output, or admin endpoints:
| Method | Content |
|---|---|
GeneratePerformanceReport() | Configuration, entry counts, utilization, memory and efficiency, then the recommendations. |
GenerateCompactStatusReport() | One-paragraph summary suitable for log lines. |
GenerateCacheAnalysisReport() | Deeper analytical view — each store's count against MaxCacheSize, tracking records, eviction size, and memory distribution. |
GetQuickHealthSummary() | One line: a status icon, the total entry count, and total memory. |
Structured monitoring data
For dashboards or metrics scrapers, GenerateMonitoringReport returns a Dictionary<string, object> with the same information in a structured form.
Health alerts
GenerateHealthAlerts(...) evaluates the cache against aHealthAlertsInput threshold object and returns one string per rule that fires — total memory past the warning or critical threshold, mean utilization at or above 90%, tracking overhead at or above 40%, fewer than 50 entries per MB, or a single store at or above 95% of MaxCacheSize. An empty list means no rule fired.
Build the input from the active options. A bare new HealthAlertsInput() leaves Config null, fails IsValid(), and comes back as one "ERROR: Invalid health alerts input parameters" item instead of an evaluation.
Cache management
| Method | Effect |
|---|---|
ClearAllCaches() | Empties every store and resets all access tracking. |
ClearCache(CacheMemoryType) | Empties a single store — see CacheMemoryType. |
ForceEvictionOnAllCaches() | Runs the configured eviction strategy on every store immediately, regardless of current size. |
IsCacheFull(CacheMemoryType) | Returns true when the target store holds more than MaxCacheSize entries — the test is strictly greater, not equal. |
Full example
The most-used calls in one place:
// Get structured statistics
CacheStatistics stats = CacheExpose.GetCacheStatistics();
CacheConfiguration config = CacheExpose.GetCacheConfiguration();
CacheMemoryUsage memory = CacheExpose.GetMemoryUsage();
// Generate reports
string perfReport = CacheExpose.GeneratePerformanceReport();
string compactReport = CacheExpose.GenerateCompactStatusReport();
string analysisReport = CacheExpose.GenerateCacheAnalysisReport();
string healthSummary = CacheExpose.GetQuickHealthSummary();
// Monitoring data for dashboards
Dictionary<string, object> monitoringData = CacheExpose.GenerateMonitoringReport();
// Health alerts — the input needs the active options, or you get one ERROR item back
var alerts = CacheExpose.GenerateHealthAlerts(
HealthAlertsInput.WithDefaults(CacheExpose.GetCacheConfigOptions()));
// Cache management
CacheExpose.ClearAllCaches();
CacheExpose.ClearCache(CacheMemoryType.PropertyPath);
CacheExpose.ForceEvictionOnAllCaches();
bool isFull = CacheExpose.IsCacheFull(CacheMemoryType.TypeProperties);