pub struct TextShapeCache { /* private fields */ }Expand description
Tier 2: bounded global LRU shaping cache.
Stores shaped text results keyed by (FontId, font_size_bits, text_hash). Evicts least-recently-used entries when the total
memory budget is exceeded.
The cache tracks access order via an internal age counter. Each access updates the entry’s age. When the budget is exceeded, the oldest entries are evicted first.
§Examples
use martensite_text::TextShapeCache;
let cache = TextShapeCache::with_default_budget();
assert!(cache.is_empty());
assert_eq!(cache.budget(), 16 * 1024 * 1024);Implementations§
Source§impl TextShapeCache
impl TextShapeCache
Sourcepub fn with_default_budget() -> Self
pub fn with_default_budget() -> Self
Creates a cache with the default 16 MB budget.
Sourcepub fn total_memory(&self) -> usize
pub fn total_memory(&self) -> usize
Returns the total estimated memory usage in bytes.
Sourcepub fn get(&mut self, key: &ShapeCacheKey) -> Option<&CachedShape>
pub fn get(&mut self, key: &ShapeCacheKey) -> Option<&CachedShape>
Looks up a cached shape by key.
Returns Some(&CachedShape) on hit, None on miss. Updates
the entry’s access age on hit.
Sourcepub fn insert(&mut self, key: ShapeCacheKey, shape: CachedShape)
pub fn insert(&mut self, key: ShapeCacheKey, shape: CachedShape)
Inserts a shaped result into the cache.
If the entry’s memory pushes the total over budget, LRU entries are evicted until the budget is satisfied.
Sourcepub fn trim(&mut self, keep_age: u64)
pub fn trim(&mut self, keep_age: u64)
Trims entries that haven’t been accessed in keep_age ticks.
This is a softer eviction than the memory-based eviction in
Self::insert.
Sourcepub fn invalidate_font(&mut self, font_id: FontId)
pub fn invalidate_font(&mut self, font_id: FontId)
Invalidates all entries for a specific font (e.g., when a font is unloaded or changed).
Sourcepub fn invalidate_font_size(&mut self, font_size: f32)
pub fn invalidate_font_size(&mut self, font_size: f32)
Invalidates all entries for a specific font size.