pub struct CachedCdnClient { /* private fields */ }Expand description
A caching wrapper around CdnClient
Implementations§
Source§impl CachedCdnClient
impl CachedCdnClient
Sourcepub async fn for_product(product: &str) -> Result<Self>
pub async fn for_product(product: &str) -> Result<Self>
Create a new cached client for a specific product
Sourcepub async fn with_cache_dir(cache_dir: PathBuf) -> Result<Self>
pub async fn with_cache_dir(cache_dir: PathBuf) -> Result<Self>
Create a new cached client with custom cache directory
Sourcepub async fn with_client(client: CdnClient) -> Result<Self>
pub async fn with_client(client: CdnClient) -> Result<Self>
Create from an existing CDN client
Sourcepub fn set_caching_enabled(&mut self, enabled: bool)
pub fn set_caching_enabled(&mut self, enabled: bool)
Enable or disable caching
Sourcepub async fn request(&self, url: &str) -> Result<Response>
pub async fn request(&self, url: &str) -> Result<Response>
Make a basic request to a CDN URL
This method does not use caching as it’s for arbitrary URLs.
Use download for hash-based content that should be cached.
Sourcepub async fn download(
&self,
cdn_host: &str,
path: &str,
hash: &str,
) -> Result<CachedResponse>
pub async fn download( &self, cdn_host: &str, path: &str, hash: &str, ) -> Result<CachedResponse>
Download content from CDN by hash with caching
If caching is enabled and the content exists in cache, it will be returned without making a network request. Otherwise, the content is downloaded from the CDN and stored in cache for future use.
Sourcepub async fn download_stream(
&self,
cdn_host: &str,
path: &str,
hash: &str,
) -> Result<Box<dyn AsyncRead + Unpin + Send>>
pub async fn download_stream( &self, cdn_host: &str, path: &str, hash: &str, ) -> Result<Box<dyn AsyncRead + Unpin + Send>>
Stream download content from CDN with caching
For large files, this method allows streaming the content while still benefiting from caching. If the content is cached, it opens the file for streaming. Otherwise, it downloads and caches the content first.
Sourcepub async fn cached_size(&self, path: &str, hash: &str) -> Result<Option<u64>>
pub async fn cached_size(&self, path: &str, hash: &str) -> Result<Option<u64>>
Get the size of cached content without reading it
Sourcepub async fn clear_cache(&self) -> Result<()>
pub async fn clear_cache(&self) -> Result<()>
Clear all cached content
This removes all cached CDN content from disk. Use with caution as it will require re-downloading all content.
Sourcepub async fn cache_stats(&self) -> Result<CacheStats>
pub async fn cache_stats(&self) -> Result<CacheStats>
Get cache statistics
Sourcepub async fn download_build_config(
&self,
cdn_host: &str,
path: &str,
hash: &str,
) -> Result<CachedResponse>
pub async fn download_build_config( &self, cdn_host: &str, path: &str, hash: &str, ) -> Result<CachedResponse>
Download BuildConfig from CDN with caching
BuildConfig files are stored at {path}/config/{hash}
Sourcepub async fn download_cdn_config(
&self,
cdn_host: &str,
path: &str,
hash: &str,
) -> Result<CachedResponse>
pub async fn download_cdn_config( &self, cdn_host: &str, path: &str, hash: &str, ) -> Result<CachedResponse>
Download CDNConfig from CDN with caching
CDNConfig files are stored at {path}/config/{hash}
Sourcepub async fn download_product_config(
&self,
cdn_host: &str,
config_path: &str,
hash: &str,
) -> Result<CachedResponse>
pub async fn download_product_config( &self, cdn_host: &str, config_path: &str, hash: &str, ) -> Result<CachedResponse>
Download ProductConfig from CDN with caching
ProductConfig files are stored at {config_path}/{hash}
Note: This uses the config_path from CDN response, not the regular path
Sourcepub async fn download_key_ring(
&self,
cdn_host: &str,
path: &str,
hash: &str,
) -> Result<CachedResponse>
pub async fn download_key_ring( &self, cdn_host: &str, path: &str, hash: &str, ) -> Result<CachedResponse>
Download KeyRing from CDN with caching
KeyRing files are stored at {path}/config/{hash}
Sourcepub async fn download_data(
&self,
cdn_host: &str,
path: &str,
hash: &str,
) -> Result<CachedResponse>
pub async fn download_data( &self, cdn_host: &str, path: &str, hash: &str, ) -> Result<CachedResponse>
Download data file from CDN with caching
Data files are stored at {path}/data/{hash}
Sourcepub async fn download_patch(
&self,
cdn_host: &str,
path: &str,
hash: &str,
) -> Result<CachedResponse>
pub async fn download_patch( &self, cdn_host: &str, path: &str, hash: &str, ) -> Result<CachedResponse>
Download patch file from CDN with caching
Patch files are stored at {path}/patch/{hash}