Struct aws_credential_types::cache::ExpiringCache
source · pub struct ExpiringCache<T, E> { /* private fields */ }
Expand description
Expiry-aware cache
ExpiringCache
implements two important features:
- Respect expiry of contents
- Deduplicate load requests to prevent thundering herds when no value is present.
Implementations§
source§impl<T, E> ExpiringCache<T, E>where
T: Clone,
impl<T, E> ExpiringCache<T, E>where T: Clone,
sourcepub async fn get_or_load<F, Fut>(&self, f: F) -> Result<T, E>where
F: FnOnce() -> Fut,
Fut: Future<Output = Result<(T, SystemTime), E>>,
pub async fn get_or_load<F, Fut>(&self, f: F) -> Result<T, E>where F: FnOnce() -> Fut, Fut: Future<Output = Result<(T, SystemTime), E>>,
Attempts to refresh the cached value with the given future.
If multiple threads attempt to refresh at the same time, one of them will win,
and the others will await that thread’s result rather than multiple refreshes occurring.
The function given to acquire a value future, f
, will not be called
if another thread is chosen to load the value.
sourcepub async fn yield_or_clear_if_expired(&self, now: SystemTime) -> Option<T>
pub async fn yield_or_clear_if_expired(&self, now: SystemTime) -> Option<T>
If the value is expired, clears the cache. Otherwise, yields the current value.
Trait Implementations§
source§impl<T, E> Clone for ExpiringCache<T, E>
impl<T, E> Clone for ExpiringCache<T, E>
Auto Trait Implementations§
impl<T, E> !RefUnwindSafe for ExpiringCache<T, E>
impl<T, E> Send for ExpiringCache<T, E>where E: Send, T: Send + Sync,
impl<T, E> Sync for ExpiringCache<T, E>where E: Sync, T: Send + Sync,
impl<T, E> Unpin for ExpiringCache<T, E>where E: Unpin,
impl<T, E> !UnwindSafe for ExpiringCache<T, E>
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