Sha256: b47079ac5d7ebd526f449bfb604d7b9a011afae452e2f0a59e97cf24940f31ac

Contents?: true

Size: 1.47 KB

Versions: 7

Compression:

Stored size: 1.47 KB

Contents

module Nanoc::Int
  # Represents a cache than can be used to store already compiled content,
  # to prevent it from being needlessly recompiled.
  #
  # @api private
  class CompiledContentCache < ::Nanoc::Int::Store
    def initialize(env_name: nil)
      super(Nanoc::Int::Store.tmp_path_for(env_name: env_name, store_name: 'compiled_content'), 2)

      @cache = {}
    end

    # Returns the cached compiled content for the given item
    # representation. This cached compiled content is a hash where the keys
    # are the snapshot names and the values the compiled content at the
    # given snapshot.
    #
    # @param [Nanoc::Int::ItemRep] rep The item rep to fetch the content for
    #
    # @return [Hash<Symbol,String>] A hash containing the cached compiled
    #   content for the given item representation
    def [](rep)
      item_cache = @cache[rep.item.identifier] || {}
      item_cache[rep.name]
    end

    # Sets the compiled content for the given representation.
    #
    # @param [Nanoc::Int::ItemRep] rep The item representation for which to set
    #   the compiled content
    #
    # @param [Hash<Symbol,String>] content A hash containing the compiled
    #   content of the given representation
    #
    # @return [void]
    def []=(rep, content)
      @cache[rep.item.identifier] ||= {}
      @cache[rep.item.identifier][rep.name] = content
    end

    protected

    def data
      @cache
    end

    def data=(new_data)
      @cache = new_data
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
nanoc-4.4.2 lib/nanoc/base/repos/compiled_content_cache.rb
nanoc-4.4.1 lib/nanoc/base/repos/compiled_content_cache.rb
nanoc-4.4.0 lib/nanoc/base/repos/compiled_content_cache.rb
nanoc-4.3.8 lib/nanoc/base/repos/compiled_content_cache.rb
nanoc-4.3.7 lib/nanoc/base/repos/compiled_content_cache.rb
nanoc-4.3.6 lib/nanoc/base/repos/compiled_content_cache.rb
nanoc-4.3.5 lib/nanoc/base/repos/compiled_content_cache.rb