pub struct LobeCache { /* private fields */ }Expand description
Cache for lobe outputs, keyed by (lobe_name, input_hash).
§Example
use pe_core::lobe_cache::LobeCache;
use pe_core::lobe::LobeOutput;
use std::time::Duration;
let mut cache = LobeCache::new(Duration::from_secs(60));
let output = LobeOutput::new("cached result", 0.9);
cache.put("analyst", "analyze this code", output.clone());
assert_eq!(
cache.get("analyst", "analyze this code").map(|o| o.content.as_str()),
Some("cached result"),
);
// Different input → cache miss
assert!(cache.get("analyst", "different input").is_none());Implementations§
Source§impl LobeCache
impl LobeCache
Sourcepub fn get(&self, lobe_name: &str, input: &str) -> Option<&LobeOutput>
pub fn get(&self, lobe_name: &str, input: &str) -> Option<&LobeOutput>
Look up a cached result. Returns None on miss or expiry.
Sourcepub fn put(&mut self, lobe_name: &str, input: &str, output: LobeOutput)
pub fn put(&mut self, lobe_name: &str, input: &str, output: LobeOutput)
Store a result in the cache.
Sourcepub fn evict_expired(&mut self)
pub fn evict_expired(&mut self)
Remove all expired entries.
Auto Trait Implementations§
impl Freeze for LobeCache
impl RefUnwindSafe for LobeCache
impl Send for LobeCache
impl Sync for LobeCache
impl Unpin for LobeCache
impl UnsafeUnpin for LobeCache
impl UnwindSafe for LobeCache
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