pub struct TranspilationCache { /* private fields */ }Expand description
Transpilation cache for avoiding re-transpilation of unchanged files.
Uses SHA-256 hashing to detect file changes and supports disk persistence. Provides 10-20x speedup on cache hits.
§Examples
use decy_core::{TranspilationCache, ProjectContext, transpile_file};
use std::path::Path;
let mut cache = TranspilationCache::new();
let path = Path::new("src/main.c");
let context = ProjectContext::new();
// First transpilation - cache miss
let result = transpile_file(path, &context)?;
cache.insert(path, &result);
// Second access - cache hit (if file unchanged)
if let Some(cached) = cache.get(path) {
println!("Cache hit! Using cached result");
}Implementations§
Source§impl TranspilationCache
impl TranspilationCache
Sourcepub fn with_directory(cache_dir: &Path) -> Self
pub fn with_directory(cache_dir: &Path) -> Self
Create a cache with a specific directory for persistence.
Sourcepub fn compute_hash(&self, path: &Path) -> Result<String>
pub fn compute_hash(&self, path: &Path) -> Result<String>
Compute SHA-256 hash of a file’s content.
Returns a 64-character hex string.
Sourcepub fn insert(&mut self, path: &Path, transpiled: &TranspiledFile)
pub fn insert(&mut self, path: &Path, transpiled: &TranspiledFile)
Insert a transpiled file into the cache.
Sourcepub fn get(&mut self, path: &Path) -> Option<&TranspiledFile>
pub fn get(&mut self, path: &Path) -> Option<&TranspiledFile>
Get a cached transpilation result if the file hasn’t changed.
Returns None if:
- File is not in cache
- File content has changed
- Any dependency has changed
Sourcepub fn statistics(&self) -> CacheStatistics
pub fn statistics(&self) -> CacheStatistics
Get cache statistics.
Trait Implementations§
Source§impl Clone for TranspilationCache
impl Clone for TranspilationCache
Source§fn clone(&self) -> TranspilationCache
fn clone(&self) -> TranspilationCache
Returns a duplicate of the value. Read more
1.0.0 · 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 TranspilationCache
impl Debug for TranspilationCache
Auto Trait Implementations§
impl Freeze for TranspilationCache
impl RefUnwindSafe for TranspilationCache
impl Send for TranspilationCache
impl Sync for TranspilationCache
impl Unpin for TranspilationCache
impl UnsafeUnpin for TranspilationCache
impl UnwindSafe for TranspilationCache
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