Skip to main content

CachedCredentials

Struct CachedCredentials 

Source
pub struct CachedCredentials<S> { /* private fields */ }
Expand description

Caches credentials per provider until shortly before they expire.

  • Credentials without expires_at_ms are cached until CredentialSource::invalidate or until the wrapped source’s CredentialSource::generation changes (e.g. the host registered a different key source or signed the user out).
  • Concurrent requests for the same provider share one fetch. If that fetch fails, every request that was waiting behind it gets the same error instead of retrying the failing fetch one after another.
  • A fetch that does not finish within the fetch timeout (default 15 s) fails with LlmError::Auth. The timeout needs a Tokio runtime; elsewhere fetches are not time-limited.
  • invalidate drops the cached value and forwards to the inner source.

Implementations§

Source§

impl<S: CredentialSource> CachedCredentials<S>

Source

pub fn new(inner: S) -> Self

Source

pub fn refresh_skew_ms(self, skew_ms: u64) -> Self

Refresh this many milliseconds before expiry.

Source

pub fn fetch_timeout(self, timeout: Duration) -> Self

Fail a fetch from the wrapped source after this long.

Source

pub fn inner(&self) -> &S

The wrapped source.

Source

pub fn clear(&self)

Drop every cached credential (all providers).

Trait Implementations§

Source§

impl<S: CredentialSource> CredentialSource for CachedCredentials<S>

Source§

fn credential<'a>( &'a self, provider: &'a str, ) -> BoxFuture<'a, Result<Credential, LlmError>>

Credential for provider (the registry name, e.g. openai).
Source§

fn invalidate(&self, provider: &str)

Called when the provider rejected the last credential (HTTP 401/403), so cached values can be dropped before one retry.
Source§

fn generation(&self) -> u64

A counter that changes whenever credentials this source would return for any provider may have changed outside of CredentialSource::invalidate (e.g. the host app signed a user out or registered a new key source). CachedCredentials drops cached values when it changes. Default: never changes.
Source§

impl<S> Debug for CachedCredentials<S>
where S: Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<S> !Freeze for CachedCredentials<S>

§

impl<S> Forget for CachedCredentials<S>

§

impl<S> Move for CachedCredentials<S>

§

impl<S> RefUnwindSafe for CachedCredentials<S>
where S: RefUnwindSafe,

§

impl<S> Send for CachedCredentials<S>
where S: Send,

§

impl<S> Sync for CachedCredentials<S>
where S: Sync,

§

impl<S> Unpin for CachedCredentials<S>
where S: Unpin,

§

impl<S> UnsafeUnpin for CachedCredentials<S>
where S: UnsafeUnpin,

§

impl<S> UnwindSafe for CachedCredentials<S>
where S: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more