Class: Nanoc::Core::CompiledContentCache Private

Inherits:
Object
  • Object
show all
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 Method Summary collapse

Methods included from ContractsSupport

enabled?, included, setup_once, warn_about_performance

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.



49
50
51
52
# File 'lib/nanoc/core/compiled_content_cache.rb', line 49

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).

Returns:

  • (Boolean)


60
61
62
# File 'lib/nanoc/core/compiled_content_cache.rb', line 60

def full_cache_available?(rep)
  @textual_cache.include?(rep) && @binary_cache.include?(rep)
end

#include?(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.

Returns:

  • (Boolean)


39
40
41
# File 'lib/nanoc/core/compiled_content_cache.rb', line 39

def include?(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.



64
65
66
# File 'lib/nanoc/core/compiled_content_cache.rb', line 64

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.



54
55
56
# File 'lib/nanoc/core/compiled_content_cache.rb', line 54

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.



68
69
70
# File 'lib/nanoc/core/compiled_content_cache.rb', line 68

def store(*args)
  @wrapped_caches.each { |w| w.store(*args) }
end