pub struct TokenCache(/* private fields */);Expand description
Thread-safe token cache shared across requests within a single RestStream.
Implementations§
Source§impl TokenCache
impl TokenCache
pub fn new() -> Self
Sourcepub async fn invalidate(&self)
pub async fn invalidate(&self)
Drop any cached token so the next get_or_refresh
fetches a fresh one. Called when the API rejects the current token with a
401 — a server-side expiry (or a token with no expires_in, cached as
valid forever) that the time-based is_valid check cannot detect (F57).
Sourcepub async fn get_or_refresh(
&self,
client: &Client,
token_url: &str,
client_id: &str,
client_secret: &str,
scopes: &[String],
expiry_ratio: f64,
) -> Result<String, FaucetError>
pub async fn get_or_refresh( &self, client: &Client, token_url: &str, client_id: &str, client_secret: &str, scopes: &[String], expiry_ratio: f64, ) -> Result<String, FaucetError>
Return a valid cached token or fetch a new one.
expiry_ratio is the fraction of the server-reported expires_in
lifetime after which the token is proactively refreshed. For example,
0.9 means a token with expires_in = 3600 is refreshed after 3240 s.
Trait Implementations§
Source§impl Clone for TokenCache
impl Clone for TokenCache
Source§fn clone(&self) -> TokenCache
fn clone(&self) -> TokenCache
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for TokenCache
impl Debug for TokenCache
Source§impl Default for TokenCache
impl Default for TokenCache
Source§fn default() -> TokenCache
fn default() -> TokenCache
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl !RefUnwindSafe for TokenCache
impl !UnwindSafe for TokenCache
impl Freeze for TokenCache
impl Send for TokenCache
impl Sync for TokenCache
impl Unpin for TokenCache
impl UnsafeUnpin for TokenCache
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