Class: Primer::Octicon::Cache
- Inherits:
-
Object
- Object
- Primer::Octicon::Cache
- Defined in:
- app/lib/primer/octicon/cache.rb
Overview
:nodoc:
Constant Summary collapse
- LOOKUP =
rubocop:disable Style/MutableConstant
{}
- PRELOADED_ICONS =
Preload the top 20 used icons.
[:alert, :check, :"chevron-down", :clippy, :clock, :"dot-fill", :info, :"kebab-horizontal", :link, :lock, :mail, :pencil, :plus, :question, :repo, :search, :"shield-lock", :star, :trash, :x].freeze
Class Method Summary collapse
- .clear! ⇒ Object
-
.limit ⇒ Object
Cache size limit.
- .preload! ⇒ Object
- .read(key) ⇒ Object
- .set(key, value) ⇒ Object
Class Method Details
.clear! ⇒ Object
28 29 30 |
# File 'app/lib/primer/octicon/cache.rb', line 28 def clear! LOOKUP.clear end |
.limit ⇒ Object
Cache size limit.
17 18 19 |
# File 'app/lib/primer/octicon/cache.rb', line 17 def limit 500 end |
.preload! ⇒ Object
32 33 34 |
# File 'app/lib/primer/octicon/cache.rb', line 32 def preload! PRELOADED_ICONS.each { |icon| Primer::OcticonComponent.new(icon: icon) } end |
.read(key) ⇒ Object
12 13 14 |
# File 'app/lib/primer/octicon/cache.rb', line 12 def read(key) LOOKUP[key] end |
.set(key, value) ⇒ Object
21 22 23 24 25 26 |
# File 'app/lib/primer/octicon/cache.rb', line 21 def set(key, value) LOOKUP[key] = value # Remove first item when the cache is too large. LOOKUP.shift if LOOKUP.size > limit end |