lib/nanoc/base/repos/compiled_content_cache.rb in nanoc-4.4.2 vs lib/nanoc/base/repos/compiled_content_cache.rb in nanoc-4.4.3

- old
+ new

@@ -2,13 +2,14 @@ # Represents a cache than can be used to store already compiled content, # to prevent it from being needlessly recompiled. # # @api private class CompiledContentCache < ::Nanoc::Int::Store - def initialize(env_name: nil) + def initialize(env_name: nil, items:) super(Nanoc::Int::Store.tmp_path_for(env_name: env_name, store_name: 'compiled_content'), 2) + @items = items @cache = {} end # Returns the cached compiled content for the given item # representation. This cached compiled content is a hash where the keys @@ -43,9 +44,17 @@ def data @cache end def data=(new_data) - @cache = new_data + @cache = {} + + item_identifiers = Set.new(@items.map(&:identifier)) + + new_data.each_pair do |item_identifier, content_per_rep| + if item_identifiers.include?(item_identifier) + @cache[item_identifier] ||= content_per_rep + end + end end end end