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§
Sourcefn update(&self, file_path: &Path, rendered_content: &str) -> Result<()>
fn update(&self, file_path: &Path, rendered_content: &str) -> Result<()>
Update cache with new file hash
§Arguments
file_path- Path to the file being updatedrendered_content- Content to hash and store
Sourcefn save(&self) -> Result<()>
fn save(&self) -> Result<()>
Save cache to persistent storage (if applicable)
For in-memory caches, this is a no-op
Sourcefn stats(&self) -> Result<CacheStats>
fn stats(&self) -> Result<CacheStats>
Get cache statistics