pub struct AutoRefreshCache<C, F, Fut>where
C: Cache + Clone + Send + Sync + 'static,
F: Fn(String) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Result<Vec<u8>, CacheError>> + Send + 'static,{ /* private fields */ }Expand description
A cache wrapper that refreshes entries in the background before they expire.
When a get returns a None, the wrapper triggers a background refresh
(via refresh_fn) while still returning the miss to the caller.
Implementations§
Source§impl<C, F, Fut> AutoRefreshCache<C, F, Fut>
impl<C, F, Fut> AutoRefreshCache<C, F, Fut>
Sourcepub fn new(inner: C, refresh_fn: F, refresh_after: Duration) -> Self
pub fn new(inner: C, refresh_fn: F, refresh_after: Duration) -> Self
Creates a new auto-refresh wrapper.
Sourcepub async fn get(&self, key: &str) -> Result<Option<Vec<u8>>, CacheError>
pub async fn get(&self, key: &str) -> Result<Option<Vec<u8>>, CacheError>
Gets a value, triggering a background refresh if the entry is a miss.
Sourcepub async fn set(
&self,
key: &str,
value: Vec<u8>,
ttl: Option<Duration>,
) -> Result<(), CacheError>
pub async fn set( &self, key: &str, value: Vec<u8>, ttl: Option<Duration>, ) -> Result<(), CacheError>
Sets a value in the underlying cache.
Sourcepub async fn invalidate(&self, key: &str) -> Result<(), CacheError>
pub async fn invalidate(&self, key: &str) -> Result<(), CacheError>
Invalidates a key in the underlying cache.
Auto Trait Implementations§
impl<C, F, Fut> !RefUnwindSafe for AutoRefreshCache<C, F, Fut>
impl<C, F, Fut> !UnwindSafe for AutoRefreshCache<C, F, Fut>
impl<C, F, Fut> Freeze for AutoRefreshCache<C, F, Fut>
impl<C, F, Fut> Send for AutoRefreshCache<C, F, Fut>
impl<C, F, Fut> Sync for AutoRefreshCache<C, F, Fut>
impl<C, F, Fut> Unpin for AutoRefreshCache<C, F, Fut>
impl<C, F, Fut> UnsafeUnpin for AutoRefreshCache<C, F, Fut>
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