pub struct MCPCacheMiddleware<T> { /* private fields */ }
Expand description
MCP tool cache middleware
Implementations§
Source§impl<T> MCPCacheMiddleware<T>
impl<T> MCPCacheMiddleware<T>
Sourcepub fn new(config: &MCPCacheConfig) -> Self
pub fn new(config: &MCPCacheConfig) -> Self
Create a new MCP cache middleware
Sourcepub fn new_default() -> Self
pub fn new_default() -> Self
Create a new middleware with default configuration
Sourcepub async fn execute_tool<F, Fut>(
&self,
tool_name: &str,
parameters: HashMap<String, Value>,
tool_executor: F,
) -> Result<T>
pub async fn execute_tool<F, Fut>( &self, tool_name: &str, parameters: HashMap<String, Value>, tool_executor: F, ) -> Result<T>
Execute a tool with caching
§Errors
This function will return an error if:
- Tool execution fails
- Cache operations fail
- Serialization/deserialization fails
Sourcepub fn get_cached_result(
&self,
tool_name: &str,
parameters: &HashMap<String, Value>,
) -> Option<T>
pub fn get_cached_result( &self, tool_name: &str, parameters: &HashMap<String, Value>, ) -> Option<T>
Get a cached result without executing the tool
Sourcepub fn invalidate_tool(&self, tool_name: &str)
pub fn invalidate_tool(&self, tool_name: &str)
Invalidate cache entries for a specific tool
Sourcepub fn invalidate_all(&self)
pub fn invalidate_all(&self)
Invalidate all cache entries
Sourcepub fn get_stats(&self) -> MCPCacheStats
pub fn get_stats(&self) -> MCPCacheStats
Get cache statistics
Sourcepub fn get_cache_size(&self) -> usize
pub fn get_cache_size(&self) -> usize
Get cache size in bytes
Sourcepub fn get_utilization(&self) -> f64
pub fn get_utilization(&self) -> f64
Get cache utilization percentage
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for MCPCacheMiddleware<T>
impl<T> !RefUnwindSafe for MCPCacheMiddleware<T>
impl<T> Send for MCPCacheMiddleware<T>
impl<T> Sync for MCPCacheMiddleware<T>
impl<T> Unpin for MCPCacheMiddleware<T>
impl<T> !UnwindSafe for MCPCacheMiddleware<T>
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more