Skip to main content

gglib_core/ports/
cache_metrics_sink.rs

1//! Outbound port for recording prompt-cache reuse.
2
3/// A sink for per-request prompt-cache reuse figures.
4///
5/// The recording site — the in-process LLM adapter's response stream — writes
6/// each completed request's usage here without knowing where it lands. The
7/// proxy's dashboard implements it with an in-memory
8/// [`CacheMetricsStore`](crate::cache_metrics::CacheMetricsStore); a process
9/// with no dashboard passes no sink at all, so recording becomes a no-op. A
10/// future cross-process reporter — a `gglib chat` run posting its reuse to a
11/// running proxy — would be another implementation behind this same seam,
12/// needing no change to the adapter.
13///
14/// `cached_tokens` keeps the `Option<u32>` absent-vs-zero distinction: `None`
15/// means the upstream didn't report the field, `Some(0)` means a real full
16/// re-prefill. Implementations must not collapse the two.
17pub trait CacheMetricsSink: Send + Sync {
18    /// Record one completed request's prompt-token count and how many of those
19    /// tokens the upstream served from its KV cache.
20    fn record(&self, prompt_tokens: u32, cached_tokens: Option<u32>);
21}