pub struct TokenCache { /* private fields */ }Expand description
Thread-safe cache of broker access tokens. Cloneable handle over shared state. Holds ONLY short-lived access tokens, never a refresh token, never persisted to disk.
Keys are either a bare provider id (legacy callers) or a scoped key built
by TokenCache::scoped_key: "<storage_key>|<source scope>", where
the scope identifies the broker endpoint AND the machine principal (a
digest of the machine token — never the token itself) so a re-pointed or
re-keyed client can never reuse another principal’s cached token.
Implementations§
Source§impl TokenCache
impl TokenCache
pub fn new() -> Self
Sourcepub fn get_fresh(&self, provider: &str, margin_ms: u64) -> Option<BrokerToken>
pub fn get_fresh(&self, provider: &str, margin_ms: u64) -> Option<BrokerToken>
Return the cached token for provider only if present AND not within
margin_ms of expiry. Otherwise None (caller should fetch).
pub fn put(&self, provider: &str, token: BrokerToken)
Sourcepub fn invalidate(&self, provider: &str)
pub fn invalidate(&self, provider: &str)
Drop every cached token for provider — the legacy bare key and every
scoped (account, source) key of that provider — so a 401 or a source
switch can never leave an account’s stale token behind.
Sourcepub fn scoped_key(scope: &str, cred: &CredentialRef) -> String
pub fn scoped_key(scope: &str, cred: &CredentialRef) -> String
Cache key for one credential fetched from one source scope.
Sourcepub fn invalidate_credential(&self, scope: &str, cred: &CredentialRef)
pub fn invalidate_credential(&self, scope: &str, cred: &CredentialRef)
Drop the cached token for exactly one scoped credential.
Sourcepub fn get_unexpired(&self, provider: &str) -> Option<BrokerToken>
pub fn get_unexpired(&self, provider: &str) -> Option<BrokerToken>
Cached token if present and not PAST hard expiry (ignores the refetch margin). Used as a degraded-mode fallback when the broker is unreachable: a token slightly inside its refetch window is still better than failing.
Trait Implementations§
Source§impl Clone for TokenCache
impl Clone for TokenCache
Source§impl Debug for TokenCache
Redacting Debug — print only the cached provider names, never the tokens.
impl Debug for TokenCache
Redacting Debug — print only the cached provider names, never the tokens.