pub struct ContentCache { /* private fields */ }Expand description
Content cache for tracking file freshness
§Design
- Keyed by WorkspaceFilePath (relative path for portability)
- Stores hash + mtime for cache invalidation
- Separate from path identity concerns
§Usage
ⓘ
let mut cache = ContentCache::new();
// Register a file
let path = resolver.resolve_relative("src/lib.rs");
cache.register(&path, hash, mtime);
// Check freshness
match cache.check_freshness(&path) {
Freshness::Fresh => println!("Up to date"),
Freshness::Stale => println!("Needs rebuild"),
_ => {}
}Implementations§
Source§impl ContentCache
impl ContentCache
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Create cache with pre-allocated capacity
Sourcepub fn register(
&mut self,
path: &WorkspaceFilePath,
hash: u64,
mtime: SystemTime,
)
pub fn register( &mut self, path: &WorkspaceFilePath, hash: u64, mtime: SystemTime, )
Register or update a file in the cache
Sourcepub fn register_with_current_mtime(
&mut self,
path: &WorkspaceFilePath,
hash: u64,
) -> Result<()>
pub fn register_with_current_mtime( &mut self, path: &WorkspaceFilePath, hash: u64, ) -> Result<()>
Register a file by reading its current mtime (hash provided)
Sourcepub fn get(&self, path: &WorkspaceFilePath) -> Option<&CacheEntry>
pub fn get(&self, path: &WorkspaceFilePath) -> Option<&CacheEntry>
Get cache entry for a file
Sourcepub fn contains(&self, path: &WorkspaceFilePath) -> bool
pub fn contains(&self, path: &WorkspaceFilePath) -> bool
Check if a file is in the cache
Sourcepub fn remove(&mut self, path: &WorkspaceFilePath) -> Option<CacheEntry>
pub fn remove(&mut self, path: &WorkspaceFilePath) -> Option<CacheEntry>
Remove a file from the cache
Sourcepub fn check_freshness(&self, path: &WorkspaceFilePath) -> Freshness
pub fn check_freshness(&self, path: &WorkspaceFilePath) -> Freshness
Check freshness of a file
Compares cached mtime with current file mtime.
Sourcepub fn get_stale_files<'a>(
&self,
paths: &'a [WorkspaceFilePath],
) -> Vec<&'a WorkspaceFilePath>
pub fn get_stale_files<'a>( &self, paths: &'a [WorkspaceFilePath], ) -> Vec<&'a WorkspaceFilePath>
Get all stale files (files that have been modified)
Sourcepub fn iter(&self) -> impl Iterator<Item = (&PathBuf, &CacheEntry)>
pub fn iter(&self) -> impl Iterator<Item = (&PathBuf, &CacheEntry)>
Iterate over all entries
Trait Implementations§
Source§impl Clone for ContentCache
impl Clone for ContentCache
Source§fn clone(&self) -> ContentCache
fn clone(&self) -> ContentCache
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for ContentCache
impl Debug for ContentCache
Source§impl Default for ContentCache
impl Default for ContentCache
Source§fn default() -> ContentCache
fn default() -> ContentCache
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for ContentCache
impl RefUnwindSafe for ContentCache
impl Send for ContentCache
impl Sync for ContentCache
impl Unpin for ContentCache
impl UnsafeUnpin for ContentCache
impl UnwindSafe for ContentCache
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