Class: Nanoc::CompiledContentCache Private

Inherits:
Store
  • Object
show all
Defined in:
lib/nanoc/base/compilation/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

- (CompiledContentCache) initialize

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



11
12
13
14
15
# File 'lib/nanoc/base/compilation/compiled_content_cache.rb', line 11

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

  @cache = {}
end

Instance Method Details

- (Hash<Symbol,String>) [](rep)

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



26
27
28
29
# File 'lib/nanoc/base/compilation/compiled_content_cache.rb', line 26

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

- (void) []=(rep, content)

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::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



40
41
42
43
# File 'lib/nanoc/base/compilation/compiled_content_cache.rb', line 40

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

- (Object) unload

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.

See Also:



46
47
48
# File 'lib/nanoc/base/compilation/compiled_content_cache.rb', line 46

def unload
  @cache = {}
end