Sha256: d002e975262be07b3221a1bc1dad5c82dac869f1ee3f70768d3ad3121a44408a

Contents?: true

Size: 1.04 KB

Versions: 5

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true

module Primer
  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)
          [symbol, size, width, height].join("_")
        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| Primer::OcticonComponent.new(icon: icon) }
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
primer_view_components-0.0.54 app/lib/primer/octicon/cache.rb
primer_view_components-0.0.53 app/lib/primer/octicon/cache.rb
primer_view_components-0.0.52 app/lib/primer/octicon/cache.rb
primer_view_components-0.0.51 app/lib/primer/octicon/cache.rb
primer_view_components-0.0.50 app/lib/primer/octicon/cache.rb