Sha256: d26fe4ba2022e3d5f4470fccc136b3372de80a95aeb70804c8efb775596969d2

Contents?: true

Size: 1.11 KB

Versions: 48

Compression:

Stored size: 1.11 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)
          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| Primer::Beta::Octicon.new(icon: icon) }
        end
      end
    end
  end
end

Version data entries

48 entries across 48 versions & 2 rubygems

Version Path
openproject-primer_view_components-0.16.0 app/lib/primer/octicon/cache.rb
openproject-primer_view_components-0.15.0 app/lib/primer/octicon/cache.rb
openproject-primer_view_components-0.14.0 app/lib/primer/octicon/cache.rb
openproject-primer_view_components-0.13.1 app/lib/primer/octicon/cache.rb
primer_view_components-0.13.2 app/lib/primer/octicon/cache.rb
primer_view_components-0.13.1 app/lib/primer/octicon/cache.rb
openproject-primer_view_components-0.13.0 app/lib/primer/octicon/cache.rb
primer_view_components-0.13.0 app/lib/primer/octicon/cache.rb
primer_view_components-0.12.0 app/lib/primer/octicon/cache.rb
primer_view_components-0.11.0 app/lib/primer/octicon/cache.rb
openproject-primer_view_components-0.12.1 app/lib/primer/octicon/cache.rb
primer_view_components-0.10.0 app/lib/primer/octicon/cache.rb
openproject-primer_view_components-0.11.0 app/lib/primer/octicon/cache.rb
openproject-primer_view_components-0.10.0 app/lib/primer/octicon/cache.rb
primer_view_components-0.9.0 app/lib/primer/octicon/cache.rb
openproject-primer_view_components-0.9.1 app/lib/primer/octicon/cache.rb
openproject-primer_view_components-0.9.0 app/lib/primer/octicon/cache.rb
openproject-primer_view_components-0.8.0 app/lib/primer/octicon/cache.rb
primer_view_components-0.8.0 app/lib/primer/octicon/cache.rb
primer_view_components-0.7.0 app/lib/primer/octicon/cache.rb