SimpleCacheMetrics constructor
SimpleCacheMetrics(
- String _name
Tracks and aggregates statistics related to cache operations for a specific cache instance.
This internal metrics container collects raw events (hits, misses, puts, evictions, expirations) and exposes aggregate insights used by JetLeaf cache managers and observability layers.
Purpose
- Provide a lightweight in-memory store of cache events for a single cache instance identified by its name.
- Enable calculation of derived metrics such as hit rate and totals.
- Produce a serializable graph/summary used by monitoring, debugging, or remote telemetry subsystems via buildGraph.
Behavior
- Events are appended to plain
List<Object>buckets; entries are stored asObjectto avoid coupling to a specific key type. The stringified representation (toString()) is used when building grouped summaries. - The class is designed for instrumentation rather than long-term storage — callers may reset metrics via reset to begin a new collection window.
Related
- CacheMetrics — interface implemented by this class.
- Useful external consumers:
CacheManager, instrumentation/telemetry exporters, health checks. - Commonly referenced methods (for documentation tracking): buildGraph, getNumberOfPutOperations, getHitRate, getTotalNumberOfAccesses, reset.
Example
final metrics = SimpleCacheMetrics('userCache'); // internal per-cache metrics
metrics.recordHit('user:42');
metrics.recordPut('user:42');
final graph = metrics.buildGraph(); // structured summary for telemetry
Creates an internal metrics collector bound to a single cache instance
name. The provided _name is used when generating summaries and graphs.
Implementation
SimpleCacheMetrics(this._name);