1use super::CallableCache;
4use crate::{get_hook, get_hooks};
5use cal_core::Hook;
6use redis::RedisError;
7
8impl CallableCache {
9 pub async fn get_hooks(self, account_id: &str) -> Result<Vec<Hook>, RedisError> {
17 println!("[CallableCache::get_hooks] Getting all hooks for account: {}", account_id);
18 let hooks = get_hooks(self.remote_cache.connection.clone(), account_id).await?;
20 println!("[CallableCache::get_hooks] Retrieved {} hooks from Redis", hooks.len());
21
22 for hook in &hooks {
24 let cache_key = format!("{}:{}", account_id, hook.id);
25 println!("[CallableCache::get_hooks] Caching hook: {} with key: {}", hook.url, cache_key);
26 self.local_cache.hooks.insert(cache_key, hook.clone());
27 }
28
29 Ok(hooks)
30 }
31
32 pub async fn get_hook(
41 self,
42 account_id: &str,
43 hook_id: &str,
44 ) -> Result<Option<Hook>, RedisError> {
45 println!("[CallableCache::get_hook] Getting hook - Account: {}, Hook ID: {}", account_id, hook_id);
46 let cache_key = format!("{}:{}", account_id, hook_id);
48 if let Some(hook) = self.local_cache.hooks.get(&cache_key) {
49 println!("[CallableCache::get_hook] Found hook in local cache");
50 return Ok(Some(hook));
51 }
52
53 println!("[CallableCache::get_hook] Hook not in local cache, fetching from Redis");
55 match get_hook(self.remote_cache.connection.clone(), account_id, hook_id).await? {
56 Some(hook) => {
57 println!("[CallableCache::get_hook] Found hook in Redis: {}", hook.url);
58 self.local_cache.hooks.insert(cache_key, hook.clone());
60 Ok(Some(hook))
61 }
62 None => {
63 println!("[CallableCache::get_hook] Hook not found in Redis");
64 Ok(None)
65 }
66 }
67 }
68}