Struct aws_credential_types::cache::ExpiringCache
source · pub struct ExpiringCache<T, E> { /* private fields */ }
Expand description
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.