Skip to content

Commit

Permalink
include error mode to partial cache key
Browse files Browse the repository at this point in the history
  • Loading branch information
ggmichaelgo committed Jun 23, 2023
1 parent cca24a2 commit 15464f2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/liquid/partial_cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Liquid
class PartialCache
def self.load(template_name, context:, parse_context:)
cached_partials = context.registers[:cached_partials]
cached_partials = context.registers[:cached_partials][parse_context.error_mode] ||= {}
cached = cached_partials[template_name]
return cached if cached

Expand Down
27 changes: 27 additions & 0 deletions test/unit/partial_cache_unit_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,31 @@ def test_uses_template_name_from_template_factory

assert_equal('some/path/my_partial', partial.name)
end

def test_includes_error_mode_into_template_cache
template_factory = StubTemplateFactory.new
context = Liquid::Context.build(
registers: {
file_system: StubFileSystem.new('my_partial' => 'my partial body'),
template_factory: template_factory,
},
)

[:lax, :warn, :strict].each do |error_mode|
Liquid::PartialCache.load(
'my_partial',
context: context,
parse_context: Liquid::ParseContext.new(error_mode: error_mode),
)
end

assert_equal([:lax, :warn, :strict], context.registers[:cached_partials].keys)

[:lax, :warn, :strict].each do |error_mode|
assert_equal(
['my_partial'],
context.registers[:cached_partials][error_mode].keys,
)
end
end
end

0 comments on commit 15464f2

Please sign in to comment.