pub struct CacheConfig {
pub strategy: CacheStrategy,
pub static_ttl: CacheTtl,
pub message_ttl: CacheTtl,
}Expand description
Cache configuration for prompt caching.
Implements Anthropic’s prompt caching best practices:
- Static content (system prompt, CLAUDE.md) uses longer TTL (1 hour default)
- Dynamic content (messages) uses shorter TTL (5 minutes default)
- Long TTL content must come before short TTL content in requests
Fields§
§strategy: CacheStrategyCache strategy determining which content types to cache
static_ttl: CacheTtlTTL for static content (system prompt, tools, CLAUDE.md)
message_ttl: CacheTtlTTL for message content (last user turn)
Implementations§
Source§impl CacheConfig
impl CacheConfig
Sourcepub fn system_only() -> Self
pub fn system_only() -> Self
Create a system-only cache configuration
Sourcepub fn messages_only() -> Self
pub fn messages_only() -> Self
Create a messages-only cache configuration
Sourcepub fn with_strategy(self, strategy: CacheStrategy) -> Self
pub fn with_strategy(self, strategy: CacheStrategy) -> Self
Set the cache strategy
Sourcepub fn with_static_ttl(self, ttl: CacheTtl) -> Self
pub fn with_static_ttl(self, ttl: CacheTtl) -> Self
Set the TTL for static content
Sourcepub fn with_message_ttl(self, ttl: CacheTtl) -> Self
pub fn with_message_ttl(self, ttl: CacheTtl) -> Self
Set the TTL for message content
Sourcepub fn message_ttl_option(&self) -> Option<CacheTtl>
pub fn message_ttl_option(&self) -> Option<CacheTtl>
Get message TTL if message caching is enabled, None otherwise.
This is a convenience method to avoid duplicating the cache_messages() check at every call site.
Trait Implementations§
Source§impl Clone for CacheConfig
impl Clone for CacheConfig
Source§fn clone(&self) -> CacheConfig
fn clone(&self) -> CacheConfig
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for CacheConfig
impl Debug for CacheConfig
Auto Trait Implementations§
impl Freeze for CacheConfig
impl RefUnwindSafe for CacheConfig
impl Send for CacheConfig
impl Sync for CacheConfig
impl Unpin for CacheConfig
impl UnwindSafe for CacheConfig
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreCreates a shared type from an unshared type.