#[non_exhaustive]pub enum CacheType {
Ephemeral,
Extended,
}Expand description
Cache type for prompt caching (Anthropic-specific feature)
Controls the time-to-live (TTL) for cached prompt content. Both types offer 90% savings on cache reads, but differ in write costs and duration.
§Pricing Model
- Ephemeral writes: 1.25x base input token cost (25% premium)
- Extended writes: 2x base input token cost (100% premium)
- Cache reads (both): 0.1x base input token cost (90% savings)
§When to Use
- Ephemeral: Quick iterations, development sessions (< 5 minutes)
- Extended: Long documentation, repeated workflows (< 1 hour)
§Example
use multi_llm::{MessageAttributes, CacheType};
// Ephemeral: lower write cost, shorter TTL
let ephemeral = MessageAttributes {
cacheable: true,
cache_type: Some(CacheType::Ephemeral),
..Default::default()
};
// Extended: higher write cost, longer TTL
let extended = MessageAttributes {
cacheable: true,
cache_type: Some(CacheType::Extended),
..Default::default()
};§Break-Even Analysis
For 1000 tokens cached and reused N times:
- Ephemeral: Profitable after 1-2 reads (breaks even quickly)
- Extended: Profitable after 5-6 reads (higher initial cost)
See: https://platform.claude.com/docs/en/build-with-claude/prompt-caching
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
Ephemeral
Ephemeral cache (5-minute TTL, 1.25x write cost)
Best for development, quick iterations, and short sessions where you’ll reuse the same context multiple times within 5 minutes.
Extended
Extended cache (1-hour TTL, 2x write cost)
Best for long documentation contexts, extended workflows, or situations where you need the cache to persist across longer time periods (up to 1 hour).
Trait Implementations§
Source§impl<'de> Deserialize<'de> for CacheType
impl<'de> Deserialize<'de> for CacheType
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl Copy for CacheType
impl Eq for CacheType
impl StructuralPartialEq for CacheType
Auto Trait Implementations§
impl Freeze for CacheType
impl RefUnwindSafe for CacheType
impl Send for CacheType
impl Sync for CacheType
impl Unpin for CacheType
impl UnwindSafe for CacheType
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<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.