pub struct PromptCache { /* private fields */ }Expand description
Derives per-request cache controls for one agent session.
Implementations§
Source§impl PromptCache
impl PromptCache
Sourcepub fn new(session_key: impl Into<String>) -> Self
pub fn new(session_key: impl Into<String>) -> Self
Creates a cache controller for a session identified by session_key.
Agent runs are long and their prefixes are large, so the one-hour retention is the default: a five-minute TTL expires during ordinary think time and turns the next request into a full re-read.
Sourcepub const fn with_ttl(self, ttl: ClaudePromptCacheTtl) -> Self
pub const fn with_ttl(self, ttl: ClaudePromptCacheTtl) -> Self
Overrides the Claude cache retention.
The cache lifetime follows the retention, since Claude’s advertised TTL is exactly how long the provider promises to keep the prefix.
Sourcepub const fn with_lifetime(self, lifetime: CacheLifetime) -> Self
pub const fn with_lifetime(self, lifetime: CacheLifetime) -> Self
Overrides how long the conversation’s cache is trusted to stay warm.
A host whose provider retains prompts longer than the breakpoints ask
for (or forever) widens the idle-reassembly gap here; a lifetime of
CacheLifetime::Permanent means an idle gap never justifies a
reassembly.
Sourcepub const fn lifetime(&self) -> CacheLifetime
pub const fn lifetime(&self) -> CacheLifetime
How long the conversation’s cache stays warm.
Sourcepub const fn with_epoch(self, epoch: u32) -> Self
pub const fn with_epoch(self, epoch: u32) -> Self
Resumes a session’s key at epoch, as read back from
PromptCache::epoch on the agent being replaced.
A rebuilt agent keyed by the same session identity and epoch asks the provider for the same cache shard its predecessor warmed, instead of restarting at epoch zero.
Sourcepub fn key(&self) -> String
pub fn key(&self) -> String
The current cache key, which changes only when the prefix is rewritten.
Sourcepub fn observe_prefix(&mut self, fingerprint: u64) -> bool
pub fn observe_prefix(&mut self, fingerprint: u64) -> bool
Records the stable prefix fingerprint for the request about to be sent.
Returns true when the prefix changed, which means the previous
epoch’s cache is now unreachable.
Sourcepub fn apply(
&self,
parameters: Parameters,
messages: &[Message],
has_tools: bool,
mid_conversation_system: bool,
) -> Parameters
pub fn apply( &self, parameters: Parameters, messages: &[Message], has_tools: bool, mid_conversation_system: bool, ) -> Parameters
Applies cache controls to parameters for a request.
messages is the assembled request, has_tools says whether tool
definitions are attached, and mid_conversation_system whether the
model keeps later system messages in the conversation; all three decide
where a Claude breakpoint can legally be placed.