Sha256: 25bed957c28827c86dcde8c9e57bc234ba42848579daacf8a0fe5ac50b9c696f
Contents?: true
Size: 1.13 KB
Versions: 2
Compression:
Stored size: 1.13 KB
Contents
# frozen_string_literal: true module Yattho module Octicon # :nodoc: class Cache LOOKUP = {} # rubocop:disable Style/MutableConstant # Preload the top 20 used icons. PRELOADED_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 << self def get_key(symbol:, size:, width: nil, height: nil) attrs = { symbol: symbol, size: size, width: width, height: height } attrs.compact! attrs.hash end def read(key) LOOKUP[key] end # Cache size limit. def limit 500 end def set(key, value) LOOKUP[key] = value # Remove first item when the cache is too large. LOOKUP.shift if LOOKUP.size > limit end def clear! LOOKUP.clear end def preload! PRELOADED_ICONS.each { |icon| Yattho::Beta::Octicon.new(icon: icon) } end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
yattho_view_components-0.1.1 | app/lib/yattho/octicon/cache.rb |
yattho_view_components-0.0.1 | app/lib/yattho/octicon/cache.rb |