mirror of
https://github.com/Shopify/liquid.git
synced 2025-11-09 00:02:23 -05:00
cache included partial templates
This commit is contained in:
parent
485340713a
commit
1e309ba74b
@ -24,8 +24,7 @@ module Liquid
|
|||||||
end
|
end
|
||||||
|
|
||||||
def render(context)
|
def render(context)
|
||||||
source = _read_template_from_file_system(context)
|
partial = _load_cached_partial(context)
|
||||||
partial = Liquid::Template.parse(source)
|
|
||||||
variable = context[@variable_name || @template_name[1..-2]]
|
variable = context[@variable_name || @template_name[1..-2]]
|
||||||
|
|
||||||
context.stack do
|
context.stack do
|
||||||
@ -46,6 +45,20 @@ module Liquid
|
|||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
def _load_cached_partial(context)
|
||||||
|
cached_partials = context.registers[:cached_partials] || {}
|
||||||
|
template_name = context[@template_name]
|
||||||
|
|
||||||
|
if cached = cached_partials[template_name]
|
||||||
|
return cached
|
||||||
|
end
|
||||||
|
source = _read_template_from_file_system(context)
|
||||||
|
partial = Liquid::Template.parse(source)
|
||||||
|
cached_partials[template_name] = partial
|
||||||
|
context.registers[:cached_partials] = cached_partials
|
||||||
|
partial
|
||||||
|
end
|
||||||
|
|
||||||
def _read_template_from_file_system(context)
|
def _read_template_from_file_system(context)
|
||||||
file_system = context.registers[:file_system] || Liquid::Template.file_system
|
file_system = context.registers[:file_system] || Liquid::Template.file_system
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user