pub struct DatasetCache { /* private fields */ }Expand description
Manages caching of downloaded datasets, using both file-based and in-memory caching
This implementation uses scirs2-core::cache’s TTLSizedCache for in-memory caching, while maintaining the file-based persistence for long-term storage.
Implementations§
Source§impl DatasetCache
impl DatasetCache
Sourcepub fn new(cachedir: PathBuf) -> Self
pub fn new(cachedir: PathBuf) -> Self
Create a new dataset cache with the given cache directory and default memory cache
Sourcepub fn with_config(
cachedir: PathBuf,
cache_size: usize,
ttl_seconds: u64,
) -> Self
pub fn with_config( cachedir: PathBuf, cache_size: usize, ttl_seconds: u64, ) -> Self
Create a new dataset cache with custom settings
Sourcepub fn with_full_config(
cachedir: PathBuf,
cache_size: usize,
ttl_seconds: u64,
max_cache_size: u64,
offline_mode: bool,
) -> Self
pub fn with_full_config( cachedir: PathBuf, cache_size: usize, ttl_seconds: u64, max_cache_size: u64, offline_mode: bool, ) -> Self
Create a new dataset cache with comprehensive configuration
Sourcepub fn ensure_cachedir(&self) -> Result<()>
pub fn ensure_cachedir(&self) -> Result<()>
Create the cache directory if it doesn’t exist
Sourcepub fn get_cachedpath(&self, name: &str) -> PathBuf
pub fn get_cachedpath(&self, name: &str) -> PathBuf
Get the path to a cached file
Sourcepub fn is_cached(&self, name: &str) -> bool
pub fn is_cached(&self, name: &str) -> bool
Check if a file is already cached (either in memory or on disk)
Sourcepub fn read_cached(&self, name: &str) -> Result<Vec<u8>>
pub fn read_cached(&self, name: &str) -> Result<Vec<u8>>
Read a cached file as bytes
This method checks the in-memory cache first, and falls back to the file system if needed. When reading from the file system, the result is also stored in the in-memory cache.
Sourcepub fn write_cached(&self, name: &str, data: &[u8]) -> Result<()>
pub fn write_cached(&self, name: &str, data: &[u8]) -> Result<()>
Write data to both the file cache and memory cache
Sourcepub fn clear_cache(&self) -> Result<()>
pub fn clear_cache(&self) -> Result<()>
Clear the entire cache (both memory and file-based)
Sourcepub fn remove_cached(&self, name: &str) -> Result<()>
pub fn remove_cached(&self, name: &str) -> Result<()>
Remove a specific cached file (from both memory and file system)
Sourcepub fn hash_filename(name: &str) -> String
pub fn hash_filename(name: &str) -> String
Compute a hash for a filename or URL
Sourcepub fn get_cache_size_bytes(&self) -> Result<u64>
pub fn get_cache_size_bytes(&self) -> Result<u64>
Get the total size of the cache in bytes
Sourcepub fn set_offline_mode(&mut self, offline: bool)
pub fn set_offline_mode(&mut self, offline: bool)
Set offline mode
Sourcepub fn is_offline(&self) -> bool
pub fn is_offline(&self) -> bool
Check if cache is in offline mode
Sourcepub fn set_max_cache_size(&mut self, max_size: u64)
pub fn set_max_cache_size(&mut self, max_size: u64)
Set maximum cache size in bytes (0 for unlimited)
Sourcepub fn max_cache_size(&self) -> u64
pub fn max_cache_size(&self) -> u64
Get maximum cache size in bytes
Sourcepub fn put(&self, name: &str, data: &[u8]) -> Result<()>
pub fn put(&self, name: &str, data: &[u8]) -> Result<()>
Put data into the cache (alias for write_cached)
Sourcepub fn get_detailed_stats(&self) -> Result<DetailedCacheStats>
pub fn get_detailed_stats(&self) -> Result<DetailedCacheStats>
Get detailed cache information
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for DatasetCache
impl !RefUnwindSafe for DatasetCache
impl Send for DatasetCache
impl !Sync for DatasetCache
impl Unpin for DatasetCache
impl UnsafeUnpin for DatasetCache
impl UnwindSafe for DatasetCache
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.