Class: Nanoc::Core::CompiledContentCache Private
- Includes:
- ContractsSupport
- Defined in:
- lib/nanoc/core/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
Instance Method Summary collapse
-
#[](rep) ⇒ Object
private
Returns the cached compiled content for the given item representation.
-
#[]=(rep, content) ⇒ Object
private
Sets the compiled content for the given representation.
-
#full_cache_available?(rep) ⇒ Boolean
private
True if there is cached compiled content available for this item, and all entries are present (either textual or binary).
-
#initialize(config:) ⇒ CompiledContentCache
constructor
private
A new instance of CompiledContentCache.
- #load(*args) ⇒ Object private
- #prune(items:) ⇒ Object private
- #store(*args) ⇒ Object private
Methods included from ContractsSupport
enabled?, included, setup_once, warn_about_performance
Methods inherited from Store
#data, #data=, tmp_path_for, tmp_path_prefix
Constructor Details
#initialize(config:) ⇒ CompiledContentCache
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.
13 14 15 16 17 18 |
# File 'lib/nanoc/core/compiled_content_cache.rb', line 13 def initialize(config:) @textual_cache = Nanoc::Core::TextualCompiledContentCache.new(config:) @binary_cache = Nanoc::Core::BinaryCompiledContentCache.new(config:) @wrapped_caches = [@textual_cache, @binary_cache] end |
Instance Method Details
#[](rep) ⇒ Object
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.
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/nanoc/core/compiled_content_cache.rb', line 25 def [](rep) textual_content_map = @textual_cache[rep] binary_content_map = @binary_cache[rep] # If either the textual or the binary content cache is nil, assume the # cache is entirely absent. # # This is necessary to support the case where only textual content is # cached (which was the case in older versions of Nanoc). return nil if [textual_content_map, binary_content_map].any?(&:nil?) textual_content_map.merge(binary_content_map) end |
#[]=(rep, content) ⇒ Object
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.
Sets the compiled content for the given 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.
44 45 46 47 |
# File 'lib/nanoc/core/compiled_content_cache.rb', line 44 def []=(rep, content) @textual_cache[rep] = content.select { |_key, c| c.textual? } @binary_cache[rep] = content.select { |_key, c| c.binary? } end |
#full_cache_available?(rep) ⇒ Boolean
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.
True if there is cached compiled content available for this item, and all entries are present (either textual or binary).
55 56 57 |
# File 'lib/nanoc/core/compiled_content_cache.rb', line 55 def full_cache_available?(rep) @textual_cache.include?(rep) && @binary_cache.include?(rep) end |
#load(*args) ⇒ Object
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.
59 60 61 |
# File 'lib/nanoc/core/compiled_content_cache.rb', line 59 def load(*args) @wrapped_caches.each { |w| w.load(*args) } end |
#prune(items:) ⇒ Object
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.
49 50 51 |
# File 'lib/nanoc/core/compiled_content_cache.rb', line 49 def prune(items:) @wrapped_caches.each { |w| w.prune(items:) } end |
#store(*args) ⇒ Object
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.
63 64 65 |
# File 'lib/nanoc/core/compiled_content_cache.rb', line 63 def store(*args) @wrapped_caches.each { |w| w.store(*args) } end |