Class: Nanoc::Int::CompiledContentCache Private

Inherits:
Store
  • Object
show all
Defined in:
lib/nanoc/base/repos/compiled_content_cache.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Represents a cache than can be used to store already compiled content, to prevent it from being needlessly recompiled.

Instance Attribute Summary

Attributes inherited from Store

#filename, #version

Instance Method Summary collapse

Methods inherited from Store

#load, #no_data_found, #store, #version_mismatch_detected

Constructor Details

#initializeCompiledContentCache

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of CompiledContentCache.



7
8
9
10
11
# File 'lib/nanoc/base/repos/compiled_content_cache.rb', line 7

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

  @cache = {}
end

Instance Method Details

#[](rep) ⇒ Hash<Symbol,String>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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.

Parameters:

Returns:

  • (Hash<Symbol,String>)

    A hash containing the cached compiled content for the given item representation



22
23
24
25
# File 'lib/nanoc/base/repos/compiled_content_cache.rb', line 22

def [](rep)
  item_cache = @cache[rep.item.identifier] || {}
  item_cache[rep.name]
end

#[]=(rep, content) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Sets the compiled content for the given representation.

Parameters:

  • rep (Nanoc::Int::ItemRep)

    The item representation for which to set the compiled content

  • content (Hash<Symbol,String>)

    A hash containing the compiled content of the given representation



36
37
38
39
# File 'lib/nanoc/base/repos/compiled_content_cache.rb', line 36

def []=(rep, content)
  @cache[rep.item.identifier] ||= {}
  @cache[rep.item.identifier][rep.name] = content
end