pub struct CardCache { /* private fields */ }Expand description
A cache of agent cards for many agents: one CachingCardResolver per
card URL, each with this cache’s settings.
A supervisor that calls fifty peers holds one of these instead of fifty resolvers, and every lookup of one URL, from any clone and any task, shares that URL’s stored card and its single fetch in flight. Clones share the cache.
use std::time::Duration;
use a2a_protocol_client::ClientBuilder;
use a2a_protocol_client::discovery::CardCache;
let cards = CardCache::new()
.with_default_freshness(Duration::from_secs(300))
.with_stale_if_error(Duration::from_secs(600));
for peer in ["https://alpha.example", "https://beta.example"] {
let client = ClientBuilder::from_card(&cards.resolve(peer).await?)?.build()?;
}Every resolver of one cache sends the same request headers (its
CardFetchOptions), so a card fetched under one credential is never
returned for another (RFC 9111 §4.1): a second credential needs a second
cache. Each with_* call starts a new, empty cache.
Past with_max_entries URLs (default 1024), the
least recently used one is dropped; a resolver already handed out keeps
working, alone.
Implementations§
Source§impl CardCache
impl CardCache
Sourcepub fn new() -> CardCache
pub fn new() -> CardCache
A cache with the default options, the well-known card path, a 10% refresh jitter and room for 1024 URLs.
Sourcepub fn with_options(self, options: CardFetchOptions) -> CardCache
pub fn with_options(self, options: CardFetchOptions) -> CardCache
Every fetch sends and checks options
(CachingCardResolver::with_options).
Sourcepub fn with_pool(self, pool: &HttpPool) -> CardCache
Available on crate feature tls-rustls only.
pub fn with_pool(self, pool: &HttpPool) -> CardCache
tls-rustls only.Every fetch goes through pool (CachingCardResolver::with_pool).
Sourcepub fn with_path(self, path: impl Into<String>) -> CardCache
pub fn with_path(self, path: impl Into<String>) -> CardCache
The path of the card under each base URL. Default:
AGENT_CARD_PATH.
Sourcepub fn with_always_revalidate(self, always: bool) -> CardCache
pub fn with_always_revalidate(self, always: bool) -> CardCache
CachingCardResolver::with_always_revalidate for every URL.
Sourcepub fn with_default_freshness(self, lifetime: Duration) -> CardCache
pub fn with_default_freshness(self, lifetime: Duration) -> CardCache
CachingCardResolver::with_default_freshness for every URL.
Sourcepub fn with_stale_if_error(self, window: Duration) -> CardCache
pub fn with_stale_if_error(self, window: Duration) -> CardCache
CachingCardResolver::with_stale_if_error for every URL.
Sourcepub fn with_refresh_jitter(self, fraction: f64) -> CardCache
pub fn with_refresh_jitter(self, fraction: f64) -> CardCache
CachingCardResolver::with_refresh_jitter for every URL. Default
here: 0.1.
Sourcepub fn with_max_entries(self, max: usize) -> CardCache
pub fn with_max_entries(self, max: usize) -> CardCache
The most URLs kept; at least 1. Default: DEFAULT_MAX_ENTRIES.
Sourcepub fn resolver(
&self,
base_url: &str,
) -> Result<CachingCardResolver, ClientError>
pub fn resolver( &self, base_url: &str, ) -> Result<CachingCardResolver, ClientError>
The resolver for the card under base_url: the one this cache
already holds for that URL, or a new one with the cache’s settings.
§Errors
ClientError::InvalidEndpoint
when base_url is malformed.
Sourcepub async fn resolve(&self, base_url: &str) -> Result<AgentCard, ClientError>
pub async fn resolve(&self, base_url: &str) -> Result<AgentCard, ClientError>
The card under base_url: resolver, then
CachingCardResolver::resolve.
§Errors
Those of the two calls.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for CardCache
impl !UnwindSafe for CardCache
impl Forget for CardCache
impl Freeze for CardCache
impl Move for CardCache
impl Send for CardCache
impl Sync for CardCache
impl Unpin for CardCache
impl UnsafeUnpin for CardCache
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§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 more§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].