CacheStatistics
public struct CacheStatistics
Statistics tracker for cache performance monitoring.
Tracks counts of cache results and computes derived metrics such as total accesses
and hit rates. A lightweight report
callback can be attached to observe each record.
- Thread-safety: This type is not synchronized; coordinate access externally if needed.
-
Optional callback invoked after every record to emit the latest statistics and result.
Declaration
Swift
public var report: ((`Self`, CacheRecord) -> Void)?
-
Total number of cache accesses (invalid + null-hit + non-null-hit + miss).
Declaration
Swift
public var totalAccesses: Int { get }
-
Hit rate (excluding invalid keys). Range: 0.0 … 1.0
Declaration
Swift
public var hitRate: Double { get }
-
Overall success rate including invalid keys. Range: 0.0 … 1.0
Declaration
Swift
public var successRate: Double { get }
-
Records a cache result and triggers the optional report callback.
Declaration
Swift
public mutating func record(_ result: CacheRecord)
-
Resets all statistics and assigns a new tracing ID.
Declaration
Swift
public mutating func reset()