pub struct CacheMetricsStore {
reporting_requests: AtomicU64,
unreported_requests: AtomicU64,
prompt_tokens: AtomicU64,
cached_tokens: AtomicU64,
last: AtomicU64,
has_last: AtomicBool,
}Expand description
Running totals of prompt-cache reuse.
Lock-free: every field is an independent atomic, updated with Relaxed
ordering. The counters are a display aid, not a consistency boundary — a
dashboard tick that reads mid-update sees one request’s figures land
slightly out of step, which is invisible at a one-second refresh and not
worth a mutex on the request path.
Fields§
§reporting_requests: AtomicU64§unreported_requests: AtomicU64§prompt_tokens: AtomicU64§cached_tokens: AtomicU64§last: AtomicU64Last reporting request’s figures, packed as (prompt << 32) | cached
so the pair is written in one store and can never be read half-updated
(e.g. a new prompt count beside the previous cached count).
Validity is tracked by Self::has_last rather than by an in-band
sentinel: u64::MAX looks unreachable but is exactly what a
(u32::MAX, u32::MAX) request packs to, which would then read back as
“nothing recorded”.
has_last: AtomicBoolWhether Self::last holds a real measurement. Stored with Release
after last, and loaded with Acquire before it, so observing true
guarantees the packed pair beside it is fully written.
Implementations§
Source§impl CacheMetricsStore
impl CacheMetricsStore
Sourcepub fn record(&self, prompt_tokens: u32, cached_tokens: Option<u32>)
pub fn record(&self, prompt_tokens: u32, cached_tokens: Option<u32>)
Record a completed request’s usage figures.
cached_tokens is None when the upstream didn’t report the field;
such a request bumps only CacheUsage::unreported_requests and
leaves the token totals untouched.
Sourcepub fn snapshot(&self) -> CacheUsage
pub fn snapshot(&self) -> CacheUsage
Snapshot the current totals.
Trait Implementations§
Source§impl CacheMetricsSink for CacheMetricsStore
The in-process store is the default CacheMetricsSink: the adapter
records straight into the atomics the dashboard snapshots.
impl CacheMetricsSink for CacheMetricsStore
The in-process store is the default CacheMetricsSink: the adapter
records straight into the atomics the dashboard snapshots.