pub struct DownloadCache { /* private fields */ }Expand description
Download file cache manager with tiered L1 (Moka) + L2 (persistent) lookup.
On get_*: L1 โ miss โ L2 โ backfill L1.
On put_*: write to both layers.
Implementationsยง
Sourceยงimpl DownloadCache
impl DownloadCache
Sourcepub async fn new(config: &CacheConfig, ttl: Option<u64>) -> Result<Self>
pub async fn new(config: &CacheConfig, ttl: Option<u64>) -> Result<Self>
Create a new DownloadCache with default TTL.
ยงArguments
config- The cache configuration specifying directories, TTLs, and backend settings.ttl- Time-to-live for cache entries in seconds (optional).
ยงReturns
A new DownloadCache instance with default TTL (7 days).
ยงErrors
Returns an error if the backend initialization fails or the backend is ambiguous.
Sourcepub async fn get_by_hash(
&self,
hash: &str,
) -> Result<Option<(CachedFile, PathBuf)>>
pub async fn get_by_hash( &self, hash: &str, ) -> Result<Option<(CachedFile, PathBuf)>>
Sourcepub async fn get_by_video_and_format(
&self,
video_id: &str,
format_id: &str,
) -> Result<Option<(CachedFile, PathBuf)>>
pub async fn get_by_video_and_format( &self, video_id: &str, format_id: &str, ) -> Result<Option<(CachedFile, PathBuf)>>
Sourcepub async fn get_by_video_and_preferences(
&self,
video_id: &str,
preferences: &FormatPreferences,
) -> Result<Option<(CachedFile, PathBuf)>>
pub async fn get_by_video_and_preferences( &self, video_id: &str, preferences: &FormatPreferences, ) -> Result<Option<(CachedFile, PathBuf)>>
Sourcepub async fn get_thumbnail_by_video_id(
&self,
video_id: &str,
) -> Result<Option<(CachedThumbnail, PathBuf)>>
pub async fn get_thumbnail_by_video_id( &self, video_id: &str, ) -> Result<Option<(CachedThumbnail, PathBuf)>>
Sourcepub async fn get_subtitle_by_language(
&self,
video_id: &str,
language: &str,
) -> Result<Option<(CachedFile, PathBuf)>>
pub async fn get_subtitle_by_language( &self, video_id: &str, language: &str, ) -> Result<Option<(CachedFile, PathBuf)>>
Sourcepub async fn put_file(
&self,
source_path: &Path,
filename: impl Into<String>,
video_id: Option<String>,
format: Option<&Format>,
) -> Result<PathBuf>
pub async fn put_file( &self, source_path: &Path, filename: impl Into<String>, video_id: Option<String>, format: Option<&Format>, ) -> Result<PathBuf>
Store a file in the cache (both layers).
ยงArguments
source_path- Path to the source file.filename- Display name for the cached file.video_id- Optional video ID association.format- Optional format metadata to store alongside the file.
ยงErrors
Returns an error if the file cannot be hashed or stored.
Sourcepub async fn put_file_with_preferences(
&self,
source_path: &Path,
filename: impl Into<String>,
video_id: Option<String>,
format: Option<&Format>,
preferences: &FormatPreferences,
) -> Result<PathBuf>
pub async fn put_file_with_preferences( &self, source_path: &Path, filename: impl Into<String>, video_id: Option<String>, format: Option<&Format>, preferences: &FormatPreferences, ) -> Result<PathBuf>
Store a file in the cache with quality/codec preferences (both layers).
ยงArguments
source_path- Path to the source file.filename- Display name for the cached file.video_id- Optional video ID association.format- Optional format metadata.preferences- The format preferences used for selection.
ยงErrors
Returns an error if the file cannot be hashed or stored.
Sourcepub async fn put_thumbnail(
&self,
source_path: &Path,
filename: impl Into<String>,
video_id: String,
) -> Result<PathBuf>
pub async fn put_thumbnail( &self, source_path: &Path, filename: impl Into<String>, video_id: String, ) -> Result<PathBuf>
Sourcepub async fn put_subtitle_file(
&self,
source_path: &Path,
filename: impl Into<String>,
video_id: String,
language_code: String,
) -> Result<PathBuf>
pub async fn put_subtitle_file( &self, source_path: &Path, filename: impl Into<String>, video_id: String, language_code: String, ) -> Result<PathBuf>
Store a subtitle file in the cache (both layers).
ยงArguments
source_path- Path to the source subtitle file.filename- Display name for the cached subtitle.video_id- The video ID associated with this subtitle.language_code- The language code (e.g., โenโ, โesโ).
ยงErrors
Returns an error if the subtitle cannot be stored.
Trait Implementationsยง
Auto Trait Implementationsยง
impl !RefUnwindSafe for DownloadCache
impl !UnwindSafe for DownloadCache
impl Freeze for DownloadCache
impl Send for DownloadCache
impl Sync for DownloadCache
impl Unpin for DownloadCache
impl UnsafeUnpin for DownloadCache
Blanket Implementationsยง
Sourceยงimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Sourceยงfn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Sourceยงimpl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Sourceยงfn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Converts
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Sourceยงfn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Converts
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Sourceยงfn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Converts
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Anyโs vtable from &Traitโs.Sourceยงfn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Converts
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Anyโs vtable from &mut Traitโs.