SimpleCacheMetrics class final
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
- Implemented types
Constructors
- SimpleCacheMetrics(String _name)
- Tracks and aggregates statistics related to cache operations for a specific cache instance.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
buildGraph(
) → Map< String, Object> -
Builds a structured graph representation of the cache state and recent operations.
override
-
getHitRate(
) → double -
Returns the cache hit rate as a percentage (0.0–100.0).
override
-
getNumberOfPutOperations(
) → int -
Returns the total number of put operations.
override
-
getTotalNumberOfAccesses(
) → int -
Returns the total number of accesses, which is the sum of hits and misses.
override
-
getTotalNumberOfEvictions(
) → int -
Returns the total number of evictions that have occurred.
override
-
getTotalNumberOfExpirations(
) → int -
Returns the total number of cache expirations that have occurred.
override
-
getTotalNumberOfHits(
) → int -
Returns the total number of cache hits.
override
-
getTotalNumberOfMisses(
) → int -
Returns the total number of cache misses.
override
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
recordEviction(
Object key) → void -
Records the eviction of a cache entry identified by
key.override -
recordExpiration(
Object key) → void -
Records the expiration of a cache entry identified by
key.override -
recordHit(
Object key) → void -
Records a successful cache hit for the given
key.override -
recordMiss(
Object key) → void -
Records a cache miss for the specified
key.override -
recordPut(
Object key) → void -
Records a cache write (insert or update) operation for the given
key.override -
reset(
) → void -
Resets all metrics to zero, clearing the historical statistics.
override
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited