use super::CallableCache;
use crate::{get_asset, get_assets};
use cal_core::Asset;
use redis::RedisError;
impl CallableCache {
pub async fn get_assets(self, account_id: &str) -> Result<Vec<Asset>, RedisError> {
println!("[CallableCache::get_assets] Getting all assets for account: {}", account_id);
let assets = get_assets(self.remote_cache.connection.clone(), account_id).await?;
println!("[CallableCache::get_assets] Retrieved {} assets from Redis", assets.len());
for asset in &assets {
let cache_key = format!("{}:{}", account_id, asset.id);
println!("[CallableCache::get_assets] Caching asset: {} with key: {}", asset.id, cache_key);
self.local_cache.assets.insert(cache_key, asset.clone());
}
Ok(assets)
}
pub async fn get_asset(
self,
account_id: &str,
asset_id: &str,
) -> Result<Option<Asset>, RedisError> {
println!("[CallableCache::get_asset] Getting asset - Account: {}, Asset ID: {}", account_id, asset_id);
let cache_key = format!("{}:{}", account_id, asset_id);
if let Some(asset) = self.local_cache.assets.get(&cache_key) {
println!("[CallableCache::get_asset] Found asset in local cache");
return Ok(Some(asset));
}
println!("[CallableCache::get_asset] Asset not in local cache, fetching from Redis");
match get_asset(self.remote_cache.connection.clone(), account_id, asset_id).await? {
Some(asset) => {
println!("[CallableCache::get_asset] Found asset in Redis: {}", asset.id);
self.local_cache.assets.insert(cache_key, asset.clone());
Ok(Some(asset))
}
None => {
println!("[CallableCache::get_asset] Asset not found in Redis");
Ok(None)
}
}
}
}