ayun_cache/support/drivers/
null.rs

1use crate::{error::Error, traits::CacheDriver, CacheResult};
2use async_trait::async_trait;
3
4pub struct Null;
5
6pub fn new() -> Box<dyn CacheDriver> {
7    Box::new(Null {})
8}
9
10#[async_trait]
11impl CacheDriver for Null {
12    async fn has(&self, _key: &str) -> CacheResult<bool> {
13        Err(Error::Message(
14            "Operation not supported by null cache".into(),
15        ))
16    }
17
18    async fn get(&self, _key: &str) -> CacheResult<Option<String>> {
19        Ok(None)
20    }
21
22    async fn insert(&self, _key: &str, _value: &str) -> CacheResult<()> {
23        Err(Error::Message(
24            "Operation not supported by null cache".into(),
25        ))
26    }
27
28    async fn remove(&self, _key: &str) -> CacheResult<()> {
29        Err(Error::Message(
30            "Operation not supported by null cache".into(),
31        ))
32    }
33    async fn clear(&self) -> CacheResult<()> {
34        Err(Error::Message(
35            "Operation not supported by null cache".into(),
36        ))
37    }
38}