pub struct ToolCache<B>where
B: ToolBackend,{ /* private fields */ }Expand description
Lazily-populated, thread-safe tool schema cache.
Owns a ToolBackend (generic parameter B) and an optional include/exclude
filter that is applied when the cache is populated.
Implementations§
Source§impl<B> ToolCache<B>where
B: ToolBackend,
impl<B> ToolCache<B>where
B: ToolBackend,
Sourcepub fn new(
backend: B,
include: Option<Vec<String>>,
exclude: Option<Vec<String>>,
) -> ToolCache<B>
pub fn new( backend: B, include: Option<Vec<String>>, exclude: Option<Vec<String>>, ) -> ToolCache<B>
Create a new, empty (unpopulated) cache wrapping backend.
include: if Some, only tools whose names are in this list are kept.
exclude: if Some, tools whose names are in this list are removed.
Both filters are applied if both are specified (include then exclude).
Sourcepub fn is_populated(&self) -> bool
pub fn is_populated(&self) -> bool
Return true if the cache has been populated (either by a previous
get_all call or by refresh).
Sourcepub async fn get_all(&self) -> Result<Vec<Tool>, Error>
pub async fn get_all(&self) -> Result<Vec<Tool>, Error>
Return all cached tools, fetching from the backend on first call.
Subsequent calls return the in-memory cache without touching the backend (double-checked locking prevents redundant fetches).
Sourcepub async fn get(&self, name: &str) -> Result<Option<Tool>, Error>
pub async fn get(&self, name: &str) -> Result<Option<Tool>, Error>
Return a single tool by name, or None if not found.
Sourcepub async fn refresh(&self) -> Result<(), Error>
pub async fn refresh(&self) -> Result<(), Error>
Force a re-fetch from the backend, discarding the current cache.
Sourcepub fn invalidate(&self)
pub fn invalidate(&self)
Invalidate (clear) the cache without re-fetching.
The next call to get_all or get will re-fetch from the backend.