pub struct CachedTokenProvider<T>{ /* private fields */ }Expand description
Cache + single-flight wrapper around a TokenRefresher.
Implementations§
Source§impl<T> CachedTokenProvider<T>
impl<T> CachedTokenProvider<T>
Sourcepub fn new(refresher: Arc<dyn TokenRefresher<T>>) -> Self
pub fn new(refresher: Arc<dyn TokenRefresher<T>>) -> Self
Build with the default DEFAULT_REFRESH_BUFFER lead time.
Sourcepub fn with_refresh_buffer(
refresher: Arc<dyn TokenRefresher<T>>,
refresh_buffer: Duration,
) -> Self
pub fn with_refresh_buffer( refresher: Arc<dyn TokenRefresher<T>>, refresh_buffer: Duration, ) -> Self
Build with a custom refresh-buffer.
Sourcepub async fn current(&self) -> Result<T, CloudError>
pub async fn current(&self) -> Result<T, CloudError>
Return the current valid token, refreshing if the cached value is missing or within the refresh-buffer of expiry.
Single-flight: only one caller runs the user-supplied
TokenRefresher::refresh at a time. Other callers wait on
a Notify for the refresh to complete and then re-check
the cache. No lock is held across the user-supplied future.
Sourcepub fn invalidate(&self)
pub fn invalidate(&self)
Drop the cached value. Useful when a 401 surfaces to force a reload regardless of the recorded expiry (clock skew defence).
Auto Trait Implementations§
impl<T> !Freeze for CachedTokenProvider<T>
impl<T> !RefUnwindSafe for CachedTokenProvider<T>
impl<T> Send for CachedTokenProvider<T>
impl<T> Sync for CachedTokenProvider<T>
impl<T> Unpin for CachedTokenProvider<T>where
T: Unpin,
impl<T> UnsafeUnpin for CachedTokenProvider<T>where
T: UnsafeUnpin,
impl<T> !UnwindSafe for CachedTokenProvider<T>
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§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>
Converts
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>
Converts
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 moreCreates a shared type from an unshared type.