pub struct FileCache { /* private fields */ }Expand description
File cache for tracking uploaded files across providers.
The cache stores file references keyed by (file_path, provider) pairs.
Each entry includes the content hash to detect file changes.
Implementations§
Source§impl FileCache
impl FileCache
Sourcepub async fn open(cache_dir: PathBuf) -> Result<Self>
pub async fn open(cache_dir: PathBuf) -> Result<Self>
Open a file cache with the given cache directory.
Loads existing cache data if the cache file exists.
§Errors
Returns an error when the cache file cannot be read or parsed.
Sourcepub async fn save(&self) -> Result<()>
pub async fn save(&self) -> Result<()>
Save cache to disk.
§Errors
Returns an error when the cache directory cannot be created or file cannot be written.
Sourcepub async fn get(
&self,
file_path: &Path,
provider: &str,
) -> Result<Option<CacheEntry>>
pub async fn get( &self, file_path: &Path, provider: &str, ) -> Result<Option<CacheEntry>>
Get a cached entry for a file if it exists and is valid.
Returns None if:
- No cache entry exists
- The file has changed (hash mismatch)
- The cache entry has expired
§Errors
Returns an error when file hashing fails.
Sourcepub async fn insert(
&mut self,
file_path: &Path,
provider: &str,
reference: String,
expires_at: Option<SystemTime>,
) -> Result<()>
pub async fn insert( &mut self, file_path: &Path, provider: &str, reference: String, expires_at: Option<SystemTime>, ) -> Result<()>
Insert a new cache entry.
The content hash is computed automatically from the file.
§Errors
Returns an error when file hashing fails.
Sourcepub fn remove(&mut self, file_path: &Path, provider: &str) -> Option<CacheEntry>
pub fn remove(&mut self, file_path: &Path, provider: &str) -> Option<CacheEntry>
Remove a cache entry.
Sourcepub fn prune_expired(&mut self) -> bool
pub fn prune_expired(&mut self) -> bool
Remove all expired entries from the cache.
Returns true if any entries were removed.
Sourcepub fn expires_in(duration: Duration) -> Option<SystemTime>
pub fn expires_in(duration: Duration) -> Option<SystemTime>
Calculate expiration time from a duration.