Class: Nanoc::Int::Compiler::Phases::Cache
- Defined in:
- lib/nanoc/base/services/compiler/phases/cache.rb
Overview
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.
Instance Method Summary collapse
-
#can_reuse_content_for_rep?(rep, is_outdated:) ⇒ Boolean
-
#initialize(wrapped:, compiled_content_cache:, snapshot_repo:) ⇒ Cache
constructor
A new instance of Cache.
-
#run(rep, is_outdated:) ⇒ Object
Methods inherited from Abstract
Constructor Details
#initialize(wrapped:, compiled_content_cache:, snapshot_repo:) ⇒ Cache
Returns a new instance of Cache
9 10 11 12 13 14 |
# File 'lib/nanoc/base/services/compiler/phases/cache.rb', line 9 def initialize(wrapped:, compiled_content_cache:, snapshot_repo:) super(wrapped: wrapped) @compiled_content_cache = compiled_content_cache @snapshot_repo = snapshot_repo end |
Instance Method Details
#can_reuse_content_for_rep?(rep, is_outdated:) ⇒ Boolean
31 32 33 34 35 36 37 38 |
# File 'lib/nanoc/base/services/compiler/phases/cache.rb', line 31 def can_reuse_content_for_rep?(rep, is_outdated:) if is_outdated false else cache = @compiled_content_cache[rep] cache ? cache.none? { |_snapshot_name, content| content.binary? } : false end end |
#run(rep, is_outdated:) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/nanoc/base/services/compiler/phases/cache.rb', line 17 def run(rep, is_outdated:) if can_reuse_content_for_rep?(rep, is_outdated: is_outdated) Nanoc::Int::NotificationCenter.post(:cached_content_used, rep) @snapshot_repo.set_all(rep, @compiled_content_cache[rep]) else yield end rep.compiled = true @compiled_content_cache[rep] = @snapshot_repo.get_all(rep) end |