pub mod drivers;
use self::drivers::CacheDriver;
#[derive(thiserror::Error, Debug)]
#[allow(clippy::module_name_repetitions)]
pub enum CacheError {
#[error(transparent)]
Any(#[from] Box<dyn std::error::Error + Send + Sync>),
}
pub type CacheResult<T> = std::result::Result<T, CacheError>;
pub struct Cache {
pub driver: Box<dyn CacheDriver>,
}
impl Cache {
#[must_use]
pub fn new(driver: Box<dyn CacheDriver>) -> Self {
Self { driver }
}
pub async fn contains_key(&self, key: &str) -> CacheResult<bool> {
self.driver.contains_key(key).await
}
pub async fn get(&self, key: &str) -> CacheResult<Option<String>> {
self.driver.get(key).await
}
pub async fn insert(&self, key: &str, value: &str) -> CacheResult<()> {
self.driver.insert(key, value).await
}
pub async fn remove(&self, key: &str) -> CacheResult<()> {
self.driver.remove(key).await
}
pub async fn clear(&self) -> CacheResult<()> {
self.driver.clear().await
}
}