pub struct SessionApprovalCache { /* private fields */ }Expand description
Process-lifetime cache of AlwaysSession approvals,
keyed by ADR-020 path. Mutex-guarded — accesses are
infrequent (one per resolve at most) and short.
Implementations§
Source§impl SessionApprovalCache
impl SessionApprovalCache
pub fn new() -> Self
Sourcepub fn record_session(&self, path: impl Into<String>, ttl: Duration)
pub fn record_session(&self, path: impl Into<String>, ttl: Duration)
Cache a Session-scope approval for path with the
given TTL. The TTL comes from the dialog’s reply so a
short-lived approval drops out of the cache once the
agent’s window expires.
A second call for the same path replaces the previous entry — there is no contract on “earliest wins” or “latest wins” beyond that, but in practice the latest reply is the one the user actually saw.
Sourcepub fn is_approved(&self, path: &str) -> bool
pub fn is_approved(&self, path: &str) -> bool
true iff path has a non-expired session approval.
Expired entries are dropped lazily on this call so the
cache stays tidy without a background sweeper.
Sourcepub fn evaluate(&self, path: &str, policy: ApproveOnUsePolicy) -> ApprovalGate
pub fn evaluate(&self, path: &str, policy: ApproveOnUsePolicy) -> ApprovalGate
Decide whether the consumer must prompt before
resolving path. The single source of truth used by
alias resolvers and the MCP proxy.
Sourcepub fn forget(&self, path: &str) -> bool
pub fn forget(&self, path: &str) -> bool
Drop the cached approval for path (if any). Call after
a rotation so a freshly-rotated value re-prompts.
Returns true if an entry was removed.
Sourcepub fn clear(&self)
pub fn clear(&self)
Drop every entry. Useful when the user clears the session manually from the inventory UI.
Sourcepub fn sweep_expired(&self) -> usize
pub fn sweep_expired(&self) -> usize
Drop expired entries; returns the number swept.
Optional housekeeping — the cache is correct without
it because Self::is_approved cleans up on access.