1use crate::cache::CallableCache;
4use crate::{get_ddi, get_ddis};
5use cal_core::DDI;
6use redis::RedisError;
7
8impl CallableCache {
9 pub async fn get_ddis(self, account_id: &str) -> Result<Vec<DDI>, RedisError> {
17 println!("[CallableCache::get_ddis] Getting all DDIs for account: {}", account_id);
18 match get_ddis(self.remote_cache.connection.clone(), account_id).await {
20 Ok(ddis) => {
21 println!("[CallableCache::get_ddis] Retrieved {} DDIs from Redis", ddis.len());
22
23 for ddi in &ddis {
25 let cache_key = format!("{}:{}", account_id, ddi.id);
26 println!("[CallableCache::get_ddis] Caching DDI: {} (name: {}) with key: {}", ddi.id, ddi.name, cache_key);
27 self.local_cache.ddis.insert(cache_key, ddi.clone());
28 }
29
30 Ok(ddis)
31 }
32 Err(e) => {
33 println!("[CallableCache::get_ddis] Error retrieving DDIs from Redis: {:?}", e);
34 Err(e)
35 }
36 }
37 }
38
39 pub async fn get_ddi(self, account_id: &str, ddi_id: &str) -> Result<Option<DDI>, RedisError> {
48 println!("[CallableCache::get_ddi] Getting DDI - Account: {}, DDI ID: {}", account_id, ddi_id);
49 let cache_key = format!("{}:{}", account_id, ddi_id);
51 if let Some(ddi) = self.local_cache.ddis.get(&cache_key) {
52 println!("[CallableCache::get_ddi] Found DDI in local cache: {}", ddi.name);
53 return Ok(Some(ddi));
54 }
55
56 println!("[CallableCache::get_ddi] DDI not in local cache, fetching from Redis");
58 match get_ddi(self.remote_cache.connection.clone(), account_id, ddi_id).await {
59 Ok(Some(ddi)) => {
60 println!("[CallableCache::get_ddi] Found DDI in Redis: {} (name: {})", ddi.id, ddi.name);
61 self.local_cache.ddis.insert(cache_key, ddi.clone());
63 Ok(Some(ddi))
64 }
65 Ok(None) => {
66 println!("[CallableCache::get_ddi] DDI not found in Redis");
67 Ok(None)
68 }
69 Err(e) => {
70 println!("[CallableCache::get_ddi] Error retrieving DDI from Redis: {:?}", e);
71 Err(e)
72 }
73 }
74 }
75}