Skip to content
Clone
44c6130
32 lines 988 B Rust
use crate::context::facade::GitContext;
impl GitContext {
pub async fn cache_insert<V>(
&self,
key: &str,
value: &V,
ttl: Option<std::time::Duration>,
) -> Result<(), crate::share::errors::GitError>
where
V: serde::Serialize,
{
match ttl {
Some(ttl) => self.cache.set_json_ex(key, value, ttl).await?,
None => self.cache.set_json(key, value).await?,
}
Ok(())
}
pub async fn cache_get<V>(&self, key: &str) -> Result<Option<V>, crate::share::errors::GitError>
where
V: serde::de::DeserializeOwned,
{
Ok(self.cache.get_json(key).await?)
}
pub async fn cache_remove(&self, key: &str) -> Result<(), crate::share::errors::GitError> {
let _ = self.cache.delete(key).await?;
Ok(())
}
pub async fn cache_exists(&self, key: &str) -> Result<bool, crate::share::errors::GitError> {
Ok(self.cache.exists(key).await?)
}
}