Skip to main content

CacheCapable

Trait CacheCapable 

Source
pub trait CacheCapable: Send + Sync {
    // Required methods
    fn create_cache<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        system_instruction: &'life1 str,
        tools: &'life2 HashMap<String, Value>,
        ttl_seconds: u32,
    ) -> Pin<Box<dyn Future<Output = Result<String>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
    fn delete_cache<'life0, 'life1, 'async_trait>(
        &'life0 self,
        name: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
}
Expand description

Trait for LLM providers that support prompt caching.

Providers implementing this trait can create and delete cached content resources, enabling automatic prompt caching lifecycle management by the runner. The runner stores an Option<Arc<dyn CacheCapable>> alongside the primary Arc<dyn Llm> and calls these methods when ContextCacheConfig is active.

§Example

use adk_core::CacheCapable;

let cache_name = model
    .create_cache("You are a helpful assistant.", &tools, 600)
    .await?;
// ... use cache_name in generation requests ...
model.delete_cache(&cache_name).await?;

Required Methods§

Source

fn create_cache<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, system_instruction: &'life1 str, tools: &'life2 HashMap<String, Value>, ttl_seconds: u32, ) -> Pin<Box<dyn Future<Output = Result<String>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Create a cached content resource from the given system instruction, tool definitions, and TTL.

Returns the provider-specific cache name (e.g. "cachedContents/abc123" for Gemini) that can be attached to subsequent generation requests via GenerateContentConfig::cached_content.

Source

fn delete_cache<'life0, 'life1, 'async_trait>( &'life0 self, name: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Delete a previously created cached content resource by name.

Implementors§