use crate::cache::config::CacheConfig;
use crate::cache::files::DownloadCache;
use crate::cache::playlist::PlaylistCache;
use crate::cache::video::VideoCache;
use crate::error::Result;
#[derive(Debug)]
pub struct CacheLayer {
pub videos: VideoCache,
pub downloads: DownloadCache,
pub playlists: PlaylistCache,
}
impl CacheLayer {
pub async fn from_config(config: &CacheConfig) -> Result<Self> {
tracing::debug!(config = %config, "⚙️ Building cache layer from config");
let videos = VideoCache::new(config, config.video_ttl).await?;
let downloads = DownloadCache::new(config, config.download_ttl).await?;
let playlists = PlaylistCache::new(config, config.playlist_ttl).await?;
tracing::debug!("✅ Cache layer initialized");
Ok(Self {
videos,
downloads,
playlists,
})
}
pub async fn clean(&self) -> Result<()> {
tracing::debug!("⚙️ Cleaning all caches");
self.videos.clean().await?;
self.downloads.clean().await?;
self.playlists.clean().await?;
Ok(())
}
}