pub struct SpeculativeCache { /* private fields */ }Expand description
Cache for in-flight speculative handles, bounded by max_in_flight.
Thread-safe; all operations hold a short parking_lot::Mutex lock.
The inner Arc<Mutex<CacheInner>> is shared with the background TTL sweeper so
both operate on the same handle set (C2: no separate empty instance in the sweeper).
Implementations§
Source§impl SpeculativeCache
impl SpeculativeCache
Return a cloned Arc to the inner mutex so it can be shared with a sweeper task.
The sweeper calls SpeculativeCache::sweep_expired_inner on the shared Arc
instead of constructing a second SpeculativeCache that would have separate storage.
Sourcepub fn sweep_expired_inner(inner: &Mutex<CacheInner>)
pub fn sweep_expired_inner(inner: &Mutex<CacheInner>)
Cancel and remove all handles whose TTL deadline has passed, operating on a raw Arc.
Intended for use by the sweeper task, which holds only the Arc (not a full
SpeculativeCache wrapper).
Sourcepub fn insert(&self, handle: SpeculativeHandle)
pub fn insert(&self, handle: SpeculativeHandle)
Insert a new handle. If at capacity, evicts and cancels the oldest.
If a handle with the same key already exists it is replaced and explicitly cancelled so the underlying tokio task does not keep running (C4: no silent drop).
Sourcepub fn take_match(
&self,
tool_id: &ToolName,
args_hash: &Hash,
) -> Option<SpeculativeHandle>
pub fn take_match( &self, tool_id: &ToolName, args_hash: &Hash, ) -> Option<SpeculativeHandle>
Find and remove a handle matching tool_id + args_hash.
Sourcepub fn cancel_by_tool_id(&self, tool_id: &ToolName)
pub fn cancel_by_tool_id(&self, tool_id: &ToolName)
Remove and cancel the first handle whose tool_id matches, if any.
Used when the args hash is not known (e.g., on tool-id mismatch at dispatch time).
Sourcepub fn sweep_expired(&self)
pub fn sweep_expired(&self)
Cancel and remove all handles whose TTL deadline has passed.
Called by the sweeper task every 5 s.
Sourcepub fn cancel_all(&self)
pub fn cancel_all(&self)
Cancel and remove all remaining handles (called at turn boundary).
Auto Trait Implementations§
impl Freeze for SpeculativeCache
impl !RefUnwindSafe for SpeculativeCache
impl Send for SpeculativeCache
impl Sync for SpeculativeCache
impl Unpin for SpeculativeCache
impl UnsafeUnpin for SpeculativeCache
impl !UnwindSafe for SpeculativeCache
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
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>
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>
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request