Struct aws_smithy_runtime::expiring_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>
pub async fn get_or_load<F, Fut>(&self, f: F) -> Result<T, 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> Freeze for ExpiringCache<T, E>
impl<T, E> !RefUnwindSafe for ExpiringCache<T, E>
impl<T, E> Send for ExpiringCache<T, E>
impl<T, E> Sync for ExpiringCache<T, E>
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)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>
Creates a shared type from an unshared type.