Class: Heroicons::ViewComponent::IconCache
- Inherits:
-
Object
- Object
- Heroicons::ViewComponent::IconCache
- Defined in:
- lib/heroicons/view_component/icon_cache.rb
Class Method Summary collapse
Class Method Details
.cache_size ⇒ Object
32 33 34 |
# File 'lib/heroicons/view_component/icon_cache.rb', line 32 def cache_size @mutex.synchronize { @cache.size } end |
.clear ⇒ Object
28 29 30 |
# File 'lib/heroicons/view_component/icon_cache.rb', line 28 def clear @mutex.synchronize { @cache.clear } end |
.get(size:, variant:, name:) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/heroicons/view_component/icon_cache.rb', line 10 def get(size:, variant:, name:) key = cache_key(size: size, variant: variant, name: name) # Check cache first (fast path) cached = @mutex.synchronize { @cache[key] } return cached if cached # Load from file and cache (slow path) @mutex.synchronize do # Double-check after acquiring lock (in case another thread loaded it) return @cache[key] if @cache[key] svg_content = load_from_file(size: size, variant: variant, name: name) @cache[key] = svg_content.freeze if svg_content svg_content end end |