pub struct CachedCredentials<S> { /* private fields */ }Expand description
Caches credentials per provider until shortly before they expire.
- Credentials without
expires_at_msare cached untilCredentialSource::invalidateor until the wrapped source’sCredentialSource::generationchanges (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. invalidatedrops the cached value and forwards to the inner source.
Implementations§
Source§impl<S: CredentialSource> CachedCredentials<S>
impl<S: CredentialSource> CachedCredentials<S>
pub fn new(inner: S) -> Self
Sourcepub fn refresh_skew_ms(self, skew_ms: u64) -> Self
pub fn refresh_skew_ms(self, skew_ms: u64) -> Self
Refresh this many milliseconds before expiry.
Sourcepub fn fetch_timeout(self, timeout: Duration) -> Self
pub fn fetch_timeout(self, timeout: Duration) -> Self
Fail a fetch from the wrapped source after this long.
Trait Implementations§
Source§impl<S: CredentialSource> CredentialSource for CachedCredentials<S>
impl<S: CredentialSource> CredentialSource for CachedCredentials<S>
Source§fn credential<'a>(
&'a self,
provider: &'a str,
) -> BoxFuture<'a, Result<Credential, LlmError>>
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)
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
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.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> 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