Sha256: 6ae3420d374f494fe125a96a28a3746a7e735acdf50e8a83d17f867e5819b3b4

Contents?: true

Size: 1.07 KB

Versions: 99

Compression:

Stored size: 1.07 KB

Contents

# frozen_string_literal: true

module Primer
  module Octicon
    # :nodoc:
    class Cache
      LOOKUP = {}
      # 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

99 entries across 99 versions & 2 rubygems

Version Path
primer_view_components-0.36.5 app/lib/primer/octicon/cache.rb
openproject-primer_view_components-0.52.2 app/lib/primer/octicon/cache.rb
primer_view_components-0.36.4 app/lib/primer/octicon/cache.rb
openproject-primer_view_components-0.52.1 app/lib/primer/octicon/cache.rb
openproject-primer_view_components-0.52.0 app/lib/primer/octicon/cache.rb
primer_view_components-0.36.3 app/lib/primer/octicon/cache.rb
openproject-primer_view_components-0.51.0 app/lib/primer/octicon/cache.rb
primer_view_components-0.36.2 app/lib/primer/octicon/cache.rb
openproject-primer_view_components-0.50.1 app/lib/primer/octicon/cache.rb
openproject-primer_view_components-0.50.0 app/lib/primer/octicon/cache.rb
primer_view_components-0.36.1 app/lib/primer/octicon/cache.rb
primer_view_components-0.36.0 app/lib/primer/octicon/cache.rb
openproject-primer_view_components-0.49.2 app/lib/primer/octicon/cache.rb
primer_view_components-0.35.2 app/lib/primer/octicon/cache.rb
openproject-primer_view_components-0.49.1 app/lib/primer/octicon/cache.rb
openproject-primer_view_components-0.49.0 app/lib/primer/octicon/cache.rb
primer_view_components-0.35.1 app/lib/primer/octicon/cache.rb
primer_view_components-0.35.0 app/lib/primer/octicon/cache.rb
openproject-primer_view_components-0.48.2 app/lib/primer/octicon/cache.rb
openproject-primer_view_components-0.48.1 app/lib/primer/octicon/cache.rb