class Nanoc::Core::CompiledContentCache
Represents a cache than can be used to store already compiled content, to prevent it from being needlessly recompiled.
@api private
Public Class Methods
new(config:)
click to toggle source
# File lib/nanoc/core/compiled_content_cache.rb, line 13 def initialize(config:) @textual_cache = Nanoc::Core::TextualCompiledContentCache.new(config: config) @binary_cache = Nanoc::Core::BinaryCompiledContentCache.new(config: config) @wrapped_caches = [@textual_cache, @binary_cache] end
Public Instance Methods
[](rep)
click to toggle source
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.
# 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)
click to toggle source
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.
# 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)
click to toggle source
True if there is cached compiled content available for this item, and all entries are present (either textual or binary).
# 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)
click to toggle source
# File lib/nanoc/core/compiled_content_cache.rb, line 59 def load(*args) @wrapped_caches.each { |w| w.load(*args) } end
prune(items:)
click to toggle source
# File lib/nanoc/core/compiled_content_cache.rb, line 49 def prune(items:) @wrapped_caches.each { |w| w.prune(items: items) } end
store(*args)
click to toggle source
# File lib/nanoc/core/compiled_content_cache.rb, line 63 def store(*args) @wrapped_caches.each { |w| w.store(*args) } end