Skip to main content

CacheMetricsStore

Struct CacheMetricsStore 

Source
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: AtomicU64

Last 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: AtomicBool

Whether 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

Source

pub fn new() -> Self

Create an empty store.

Source

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.

Source

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.

Source§

fn record(&self, prompt_tokens: u32, cached_tokens: Option<u32>)

Record one completed request’s prompt-token count and how many of those tokens the upstream served from its KV cache.
Source§

impl Debug for CacheMetricsStore

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for CacheMetricsStore

Source§

fn default() -> CacheMetricsStore

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more