Cache

Trait Cache 

Source
pub trait Cache: Send + Sync {
    // Required methods
    fn has_changed(
        &self,
        file_path: &Path,
        rendered_content: &str,
    ) -> Result<bool>;
    fn update(&self, file_path: &Path, rendered_content: &str) -> Result<()>;
    fn remove(&self, file_path: &Path) -> Result<()>;
    fn save(&self) -> Result<()>;
    fn stats(&self) -> Result<CacheStats>;
    fn clear(&self) -> Result<()>;
}
Expand description

Cache trait defining the contract for cache backends

London School TDD:

  • This trait defines the collaboration contract
  • Implementations can be mocked for testing
  • Focuses on behavior verification over state

§Design Principles

  • All methods return Result for proper error handling
  • Thread-safe implementations required (Clone + Send + Sync)
  • No async to maintain dyn compatibility

Required Methods§

Source

fn has_changed(&self, file_path: &Path, rendered_content: &str) -> Result<bool>

Check if a file has changed since last cache update

§Arguments
  • file_path - Path to the file being checked
  • rendered_content - Current content to compare against cache
§Returns
  • Ok(true) if file changed or not in cache
  • Ok(false) if file unchanged
  • Err if operation fails
Source

fn update(&self, file_path: &Path, rendered_content: &str) -> Result<()>

Update cache with new file hash

§Arguments
  • file_path - Path to the file being updated
  • rendered_content - Content to hash and store
Source

fn remove(&self, file_path: &Path) -> Result<()>

Remove a file from cache

§Arguments
  • file_path - Path to the file being removed
Source

fn save(&self) -> Result<()>

Save cache to persistent storage (if applicable)

For in-memory caches, this is a no-op

Source

fn stats(&self) -> Result<CacheStats>

Get cache statistics

Source

fn clear(&self) -> Result<()>

Clear all cache entries

Implementors§