Class: Primer::Octicon::Cache
- Inherits:
-
Object
- Object
- Primer::Octicon::Cache
- Defined in:
- app/lib/primer/octicon/cache.rb
Overview
:nodoc:
Constant Summary collapse
- LOOKUP =
{}
- PRELOADED_ICONS =
Preload the top 20 used icons.
[:alert, :check, :"chevron-down", :paste, :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
- .get_key(symbol:, size:, width: nil, height: nil) ⇒ Object
-
.limit ⇒ Object
Cache size limit.
- .preload! ⇒ Object
- .read(key) ⇒ Object
- .set(key, value) ⇒ Object
Class Method Details
permalink .clear! ⇒ Object
[View source]
34 35 36 |
# File 'app/lib/primer/octicon/cache.rb', line 34 def clear! LOOKUP.clear end |
permalink .get_key(symbol:, size:, width: nil, height: nil) ⇒ Object
[View source]
12 13 14 15 16 |
# File 'app/lib/primer/octicon/cache.rb', line 12 def get_key(symbol:, size:, width: nil, height: nil) attrs = { symbol: symbol, size: size, width: width, height: height } attrs.compact! attrs.hash end |
permalink .limit ⇒ Object
Cache size limit.
23 24 25 |
# File 'app/lib/primer/octicon/cache.rb', line 23 def limit 500 end |
permalink .preload! ⇒ Object
[View source]
38 39 40 |
# File 'app/lib/primer/octicon/cache.rb', line 38 def preload! PRELOADED_ICONS.each { |icon| Primer::Beta::Octicon.new(icon: icon) } end |
permalink .read(key) ⇒ Object
[View source]
18 19 20 |
# File 'app/lib/primer/octicon/cache.rb', line 18 def read(key) LOOKUP[key] end |
permalink .set(key, value) ⇒ Object
[View source]
27 28 29 30 31 32 |
# File 'app/lib/primer/octicon/cache.rb', line 27 def set(key, value) LOOKUP[key] = value # Remove first item when the cache is too large. LOOKUP.shift if LOOKUP.size > limit end |