pub struct LruCompilationCache { /* private fields */ }Expand description
LRU compilation cache with configurable capacity.
Stores compiled EinsumGraph instances keyed by ExprFingerprint.
When capacity is exceeded the least-recently-used entry is evicted.
This cache is not thread-safe — wrap it in Arc<Mutex<_>> or use
CompilationCache if you need concurrent access.
§Example
use tensorlogic_compiler::cache::{LruCompilationCache, ExprFingerprint};
use tensorlogic_ir::EinsumGraph;
let mut cache = LruCompilationCache::new(4);
let fp = ExprFingerprint::compute("pred(x)");
cache.insert(fp.clone(), EinsumGraph::new());
assert!(cache.get(&fp).is_some());Implementations§
Source§impl LruCompilationCache
impl LruCompilationCache
Sourcepub fn new(capacity: usize) -> Self
pub fn new(capacity: usize) -> Self
Create a new LRU cache with the given capacity (minimum 1).
Sourcepub fn insert(&mut self, fp: ExprFingerprint, graph: EinsumGraph)
pub fn insert(&mut self, fp: ExprFingerprint, graph: EinsumGraph)
Insert a compiled result for the given fingerprint.
If the fingerprint already exists the stored graph is updated and the entry is promoted to the most-recently-used position.
If the cache is at capacity the least-recently-used entry is evicted before the new entry is inserted.
Sourcepub fn get(&mut self, fp: &ExprFingerprint) -> Option<&CachedResult>
pub fn get(&mut self, fp: &ExprFingerprint) -> Option<&CachedResult>
Look up a fingerprint.
On a hit the entry is promoted to the most-recently-used position,
its hit_count is incremented, and a reference to it is returned.
On a miss None is returned.
Sourcepub fn contains(&self, fp: &ExprFingerprint) -> bool
pub fn contains(&self, fp: &ExprFingerprint) -> bool
Check if a fingerprint is present without updating LRU order or stats.
Sourcepub fn invalidate(&mut self, fp: &ExprFingerprint) -> bool
pub fn invalidate(&mut self, fp: &ExprFingerprint) -> bool
Remove a specific entry by fingerprint.
Returns true if the entry existed and was removed, false otherwise.
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Clear all cached entries, resetting memory accounting.
Statistics counters (hits, misses, evictions) are not reset.
Sourcepub fn stats(&self) -> &CacheStats
pub fn stats(&self) -> &CacheStats
Reference to the current statistics snapshot.