simple_agents_cache/
noop.rs1use async_trait::async_trait;
4use simple_agent_type::cache::Cache;
5use simple_agent_type::error::Result;
6use std::time::Duration;
7
8#[derive(Debug, Clone, Copy, Default)]
30pub struct NoOpCache;
31
32#[async_trait]
33impl Cache for NoOpCache {
34 async fn get(&self, _key: &str) -> Result<Option<Vec<u8>>> {
35 Ok(None)
36 }
37
38 async fn set(&self, _key: &str, _value: Vec<u8>, _ttl: Duration) -> Result<()> {
39 Ok(())
40 }
41
42 async fn delete(&self, _key: &str) -> Result<()> {
43 Ok(())
44 }
45
46 async fn clear(&self) -> Result<()> {
47 Ok(())
48 }
49
50 fn is_enabled(&self) -> bool {
51 false
52 }
53
54 fn name(&self) -> &str {
55 "noop"
56 }
57}
58
59#[cfg(test)]
60mod tests {
61 use super::*;
62
63 #[tokio::test]
64 async fn test_noop_always_returns_none() {
65 let cache = NoOpCache;
66
67 cache
68 .set("key1", b"value1".to_vec(), Duration::from_secs(60))
69 .await
70 .unwrap();
71 let value = cache.get("key1").await.unwrap();
72 assert_eq!(value, None);
73 }
74
75 #[tokio::test]
76 async fn test_noop_is_disabled() {
77 let cache = NoOpCache;
78 assert!(!cache.is_enabled());
79 }
80
81 #[tokio::test]
82 async fn test_noop_name() {
83 let cache = NoOpCache;
84 assert_eq!(cache.name(), "noop");
85 }
86
87 #[tokio::test]
88 async fn test_noop_delete_does_nothing() {
89 let cache = NoOpCache;
90 cache.delete("key1").await.unwrap();
91 }
93
94 #[tokio::test]
95 async fn test_noop_clear_does_nothing() {
96 let cache = NoOpCache;
97 cache.clear().await.unwrap();
98 }
100}