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<FileCache, Error>
pub async fn open(cache_dir: PathBuf) -> Result<FileCache, Error>
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<(), Error>
pub async fn save(&self) -> Result<(), Error>
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>, Error>
pub async fn get( &self, file_path: &Path, provider: &str, ) -> Result<Option<CacheEntry>, Error>
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<(), Error>
pub async fn insert( &mut self, file_path: &Path, provider: &str, reference: String, expires_at: Option<SystemTime>, ) -> Result<(), Error>
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.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for FileCache
impl<'de> Deserialize<'de> for FileCache
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<FileCache, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<FileCache, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl Serialize for FileCache
impl Serialize for FileCache
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Auto Trait Implementations§
impl Freeze for FileCache
impl RefUnwindSafe for FileCache
impl Send for FileCache
impl Sync for FileCache
impl Unpin for FileCache
impl UnsafeUnpin for FileCache
impl UnwindSafe for FileCache
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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 more