class Nanoc::Core::CompilationPhases::Cache

Provides functionality for (re)calculating the content of an item rep, with caching or outdatedness checking. Delegates to s::Recalculate if outdated or no cache available.

Public Class Methods

new(wrapped:, compiled_content_cache:, compiled_content_store:) click to toggle source
# File lib/nanoc/core/compilation_phases/cache.rb, line 11
def initialize(wrapped:, compiled_content_cache:, compiled_content_store:)
  super(wrapped: wrapped)

  @compiled_content_cache = compiled_content_cache
  @compiled_content_store = compiled_content_store
end

Public Instance Methods

can_reuse_content_for_rep?(rep, is_outdated:) click to toggle source
# File lib/nanoc/core/compilation_phases/cache.rb, line 33
def can_reuse_content_for_rep?(rep, is_outdated:)
  if is_outdated
    false
  else
    @compiled_content_cache.full_cache_available?(rep)
  end
end
run(rep, is_outdated:) { || ... } click to toggle source
# File lib/nanoc/core/compilation_phases/cache.rb, line 19
def run(rep, is_outdated:)
  if can_reuse_content_for_rep?(rep, is_outdated: is_outdated)
    Nanoc::Core::NotificationCenter.post(:cached_content_used, rep)

    @compiled_content_store.set_all(rep, @compiled_content_cache[rep])
  else
    yield
  end

  rep.compiled = true
  @compiled_content_cache[rep] = @compiled_content_store.get_all(rep)
end