cache_any/caches/
mod.rs

1mod memory;
2pub use memory::*;
3
4#[cfg(feature = "redis")]
5mod redis;
6#[cfg(feature = "redis")]
7pub use redis::*;
8
9#[cfg(feature = "mysql")]
10mod mysql;
11#[cfg(feature = "mysql")]
12pub use mysql::*;
13
14use crate::Cacheable;
15
16/// A cache trait.
17/// 
18/// It describes the basic operations of a cache.
19/// All functions are async, because we may use async storage backends.
20#[async_trait::async_trait]
21#[allow(clippy::len_without_is_empty)]
22pub trait Cache: Clone {
23    async fn get<T: Cacheable + Send + Sync>(&self, key: &str) -> anyhow::Result<Option<T>>;
24    async fn set<T: Cacheable + Send + Sync>(&self, key: &str, value: T) -> anyhow::Result<()>;
25    async fn delete(&self, key: &str) -> anyhow::Result<()>;
26    async fn len(&self) -> anyhow::Result<usize>;
27}