Skip to main content

ContentCache

Struct ContentCache 

Source
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

Source

pub fn new() -> Self

Create a new empty cache

Source

pub fn with_capacity(capacity: usize) -> Self

Create cache with pre-allocated capacity

Source

pub fn register( &mut self, path: &WorkspaceFilePath, hash: u64, mtime: SystemTime, )

Register or update a file in the cache

Source

pub fn register_with_current_mtime( &mut self, path: &WorkspaceFilePath, hash: u64, ) -> Result<()>

Register a file by reading its current mtime (hash provided)

Source

pub fn get(&self, path: &WorkspaceFilePath) -> Option<&CacheEntry>

Get cache entry for a file

Source

pub fn contains(&self, path: &WorkspaceFilePath) -> bool

Check if a file is in the cache

Source

pub fn remove(&mut self, path: &WorkspaceFilePath) -> Option<CacheEntry>

Remove a file from the cache

Source

pub fn check_freshness(&self, path: &WorkspaceFilePath) -> Freshness

Check freshness of a file

Compares cached mtime with current file mtime.

Source

pub fn get_stale_files<'a>( &self, paths: &'a [WorkspaceFilePath], ) -> Vec<&'a WorkspaceFilePath>

Get all stale files (files that have been modified)

Source

pub fn clear(&mut self)

Clear all entries

Source

pub fn len(&self) -> usize

Get number of cached entries

Source

pub fn is_empty(&self) -> bool

Check if cache is empty

Source

pub fn iter(&self) -> impl Iterator<Item = (&PathBuf, &CacheEntry)>

Iterate over all entries

Trait Implementations§

Source§

impl Clone for ContentCache

Source§

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)

Performs copy-assignment from source. Read more
Source§

impl Debug for ContentCache

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ContentCache

Source§

fn default() -> ContentCache

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.