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.7.0 app/lib/primer/octicon/cache.rb
openproject-primer_view_components-0.6.3 app/lib/primer/octicon/cache.rb
primer_view_components-0.6.0 app/lib/primer/octicon/cache.rb
primer_view_components-0.5.1 app/lib/primer/octicon/cache.rb
primer_view_components-0.5.0 app/lib/primer/octicon/cache.rb
primer_view_components-0.4.0 app/lib/primer/octicon/cache.rb
primer_view_components-0.3.1 app/lib/primer/octicon/cache.rb
primer_view_components-0.3.0 app/lib/primer/octicon/cache.rb
primer_view_components-0.2.0 app/lib/primer/octicon/cache.rb
primer_view_components-0.1.9 app/lib/primer/octicon/cache.rb
primer_view_components-0.1.8 app/lib/primer/octicon/cache.rb
primer_view_components-0.1.7 app/lib/primer/octicon/cache.rb
primer_view_components-0.1.6 app/lib/primer/octicon/cache.rb
primer_view_components-0.1.5 app/lib/primer/octicon/cache.rb
primer_view_components-0.1.4 app/lib/primer/octicon/cache.rb
primer_view_components-0.1.3 app/lib/primer/octicon/cache.rb
primer_view_components-0.1.2 app/lib/primer/octicon/cache.rb
primer_view_components-0.1.1 app/lib/primer/octicon/cache.rb
primer_view_components-0.1.0 app/lib/primer/octicon/cache.rb
primer_view_components-0.0.123 app/lib/primer/octicon/cache.rb