pub struct LlmCachePolicy {
pub key_func: Option<Arc<dyn Fn(&LlmCacheKeyInput) -> String + Send + Sync>>,
}Expand description
Cache policy for LLM response caching
Controls how LLM responses are cached, including the ability to customize the cache key generation function.
§Examples
use juncture_tracing::types::LlmCachePolicy;
let policy = LlmCachePolicy::default();
assert!(policy.key_func.is_none());Fields§
§key_func: Option<Arc<dyn Fn(&LlmCacheKeyInput) -> String + Send + Sync>>Optional custom cache key function
If None, the default key function using (model, messages_hash) is used.
Implementations§
Source§impl LlmCachePolicy
impl LlmCachePolicy
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new cache policy with the default key function
§Examples
use juncture_tracing::types::LlmCachePolicy;
let policy = LlmCachePolicy::new();
assert!(policy.key_func.is_none());Sourcepub fn with_key_func<F>(self, f: F) -> Self
pub fn with_key_func<F>(self, f: F) -> Self
Set a custom cache key function
§Parameters
f- Function that generates cache keys from input
§Examples
use juncture_tracing::types::{LlmCachePolicy, LlmCacheKeyInput};
use serde_json::json;
let policy = LlmCachePolicy::new().with_key_func(|input| {
format!("{}:{}", input.model, input.messages.len())
});
let key_input = LlmCacheKeyInput {
model: "gpt-4".to_string(),
messages: vec![],
tools: vec![],
config: None,
};
assert!(policy.key_func.as_ref().map(|f| f(&key_input)).is_some());Trait Implementations§
Source§impl Debug for LlmCachePolicy
impl Debug for LlmCachePolicy
Source§impl Default for LlmCachePolicy
impl Default for LlmCachePolicy
Source§fn default() -> LlmCachePolicy
fn default() -> LlmCachePolicy
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl !RefUnwindSafe for LlmCachePolicy
impl !UnwindSafe for LlmCachePolicy
impl Freeze for LlmCachePolicy
impl Send for LlmCachePolicy
impl Sync for LlmCachePolicy
impl Unpin for LlmCachePolicy
impl UnsafeUnpin for LlmCachePolicy
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