Class: Yattho::Octicon::Cache

Inherits:
Object
  • Object
show all
Defined in:
app/lib/yattho/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', :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

Class Method Details

.clear!Object



35
36
37
# File 'app/lib/yattho/octicon/cache.rb', line 35

def clear!
  LOOKUP.clear
end

.get_key(symbol:, size:, width: nil, height: nil) ⇒ Object



13
14
15
16
17
# File 'app/lib/yattho/octicon/cache.rb', line 13

def get_key(symbol:, size:, width: nil, height: nil)
  attrs = { symbol: symbol, size: size, width: width, height: height }
  attrs.compact!
  attrs.hash
end

.limitObject

Cache size limit.



24
25
26
# File 'app/lib/yattho/octicon/cache.rb', line 24

def limit
  500
end

.preload!Object



39
40
41
# File 'app/lib/yattho/octicon/cache.rb', line 39

def preload!
  PRELOADED_ICONS.each { |icon| Yattho::Beta::Octicon.new(icon: icon) }
end

.read(key) ⇒ Object



19
20
21
# File 'app/lib/yattho/octicon/cache.rb', line 19

def read(key)
  LOOKUP[key]
end

.set(key, value) ⇒ Object



28
29
30
31
32
33
# File 'app/lib/yattho/octicon/cache.rb', line 28

def set(key, value)
  LOOKUP[key] = value

  # Remove first item when the cache is too large.
  LOOKUP.shift if LOOKUP.size > limit
end