pub struct CacheAside<C, F> { /* private fields */ }Expand description
A generic read-through cache-aside helper.
F is the data source: an async closure (owned key) -> Option<Vec<u8>>.
The key is passed by value (String) so the returned future does not
borrow from the caller, which keeps the API simple and 'static-friendly.
Implementations§
Source§impl<C, F, Fut> CacheAside<C, F>
impl<C, F, Fut> CacheAside<C, F>
Sourcepub fn new(cache: C, fetcher: F) -> Self
pub fn new(cache: C, fetcher: F) -> Self
Builds a cache-aside wrapper around cache using fetcher to fill
misses. Entries are stored without expiry unless with_ttl is used.
Sourcepub fn with_ttl(self, ttl: Duration) -> Self
pub fn with_ttl(self, ttl: Duration) -> Self
Applies a ttl to every entry written by this 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>
Returns a value for key, reading through to the fetcher on a miss and
caching the result.
Sourcepub async fn invalidate(&self, key: &str) -> Result<(), CacheError>
pub async fn invalidate(&self, key: &str) -> Result<(), CacheError>
Explicitly evicts key.
Trait Implementations§
Auto Trait Implementations§
impl<C, F> Freeze for CacheAside<C, F>
impl<C, F> RefUnwindSafe for CacheAside<C, F>where
C: RefUnwindSafe,
F: RefUnwindSafe,
impl<C, F> Send for CacheAside<C, F>
impl<C, F> Sync for CacheAside<C, F>
impl<C, F> Unpin for CacheAside<C, F>
impl<C, F> UnsafeUnpin for CacheAside<C, F>where
C: UnsafeUnpin,
F: UnsafeUnpin,
impl<C, F> UnwindSafe for CacheAside<C, F>where
C: UnwindSafe,
F: UnwindSafe,
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