Skip to main content

LobeCache

Struct LobeCache 

Source
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

Source

pub fn new(ttl: Duration) -> Self

Create a new cache with the given TTL.

Source

pub fn get(&self, lobe_name: &str, input: &str) -> Option<&LobeOutput>

Look up a cached result. Returns None on miss or expiry.

Source

pub fn put(&mut self, lobe_name: &str, input: &str, output: LobeOutput)

Store a result in the cache.

Source

pub fn evict_expired(&mut self)

Remove all expired entries.

Source

pub fn clear(&mut self)

Clear all entries.

Source

pub fn len(&self) -> usize

Number of entries (including potentially expired).

Source

pub fn is_empty(&self) -> bool

Whether the cache has no entries.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.