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