Sha256: e1ea181bc19fdfb5bccff186efe7ea72edbd80f5c179df4d93dac64e724093fd

Contents?: true

Size: 1.47 KB

Versions: 9

Compression:

Stored size: 1.47 KB

Contents

# encoding: utf-8

module Nanoc3

  # Represents a cache than can be used to store already compiled content,
  # to prevent it from being needlessly recompiled.
  #
  # @api private
  class CompiledContentCache < ::Nanoc3::Store

    def initialize
      super('tmp/compiled_content', 1)

      @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 [Nanoc3::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 [Nanoc3::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

    # @see Nanoc3::Store#unload
    def unload
      @cache = {}
    end

  protected

    def data
      @cache
    end

    def data=(new_data)
      @cache = new_data
    end

  end

end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
nanoc3-3.2.4 lib/nanoc3/base/compilation/compiled_content_cache.rb
nanoc3-3.2.3 lib/nanoc3/base/compilation/compiled_content_cache.rb
nanoc3-3.2.2 lib/nanoc3/base/compilation/compiled_content_cache.rb
nanoc3-3.2.1 lib/nanoc3/base/compilation/compiled_content_cache.rb
nanoc3-3.2.0 lib/nanoc3/base/compilation/compiled_content_cache.rb
nanoc3-3.2.0b3 lib/nanoc3/base/compilation/compiled_content_cache.rb
nanoc3-3.2.0b2 lib/nanoc3/base/compilation/compiled_content_cache.rb
nanoc3-3.2.0b1 lib/nanoc3/base/compilation/compiled_content_cache.rb
nanoc3-3.2.0a4 lib/nanoc3/base/compilation/compiled_content_cache.rb