pub struct Cache { /* private fields */ }Expand description
JSON get/set/remember on a KvStore.
Implementations§
Source§impl Cache
impl Cache
pub fn new(store: Arc<dyn KvStore>) -> Self
pub async fn get_json<T: DeserializeOwned>(&self, key: &str) -> Option<T>
pub async fn set_json<T: Serialize>( &self, key: &str, val: &T, ttl: Option<Duration>, ) -> Result<(), CacheError>
Sourcepub async fn remember<T, F, Fut>(
&self,
key: &str,
ttl: Option<Duration>,
f: F,
) -> Result<T, CacheError>where
T: Serialize + DeserializeOwned,
F: FnOnce() -> Fut,
Fut: Future<Output = Result<T, CacheError>>,
pub async fn remember<T, F, Fut>(
&self,
key: &str,
ttl: Option<Duration>,
f: F,
) -> Result<T, CacheError>where
T: Serialize + DeserializeOwned,
F: FnOnce() -> Fut,
Fut: Future<Output = Result<T, CacheError>>,
Return cached value or compute, store, and return.
pub async fn invalidate(&self, key: &str)
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Cache
impl !UnwindSafe for Cache
impl Freeze for Cache
impl Send for Cache
impl Sync for Cache
impl Unpin for Cache
impl UnsafeUnpin for Cache
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