pub struct CacheTracker {
pub total_cache_writes: u64,
pub total_cache_reads: u64,
pub call_count: u64,
pub hit_count: u64,
pub break_count: u64,
/* private fields */
}Expand description
Tracks cache performance across multiple API calls.
Fields§
§total_cache_writes: u64Total cache creation tokens (cache misses that create new entries).
total_cache_reads: u64Total cache read tokens (cache hits).
call_count: u64Number of API calls observed.
hit_count: u64Number of calls that had any cache reads (hits).
break_count: u64Number of calls where cache writes exceeded reads (likely break).
Implementations§
Source§impl CacheTracker
impl CacheTracker
pub fn new() -> Self
Sourcepub fn update_fingerprint(
&mut self,
system_prompt: &str,
tool_count: usize,
) -> bool
pub fn update_fingerprint( &mut self, system_prompt: &str, tool_count: usize, ) -> bool
Update the fingerprint of the cacheable request prefix. Call before each API request. Returns true if the fingerprint changed (indicating the cache will likely break).
Sourcepub fn record(&mut self, usage: &Usage) -> CacheEvent
pub fn record(&mut self, usage: &Usage) -> CacheEvent
Record usage from an API call and detect cache breaks.
Sourcepub fn estimated_savings(&self) -> f64
pub fn estimated_savings(&self) -> f64
Estimated cost savings from cache hits. Cache reads are ~10% the cost of cache writes.
Trait Implementations§
Source§impl Debug for CacheTracker
impl Debug for CacheTracker
Source§impl Default for CacheTracker
impl Default for CacheTracker
Source§fn default() -> CacheTracker
fn default() -> CacheTracker
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for CacheTracker
impl RefUnwindSafe for CacheTracker
impl Send for CacheTracker
impl Sync for CacheTracker
impl Unpin for CacheTracker
impl UnsafeUnpin for CacheTracker
impl UnwindSafe for CacheTracker
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more