[BUG] cphalcon 1.1.0 : Volt : Template Inheritance : cached templates were not recompiled after changed parent template
- template _parent.volt
- template child.volt , as {% extends _parent.volt %}
- load page "child", check cached & compiled template's dir - they are ok
- edit _parent.volt
- load page "child"
- error: there are no changes on the page
Now we have: cached version of child.volt was not recompiled, page based on child.volt has no changes
Should be: changes of _parent.volt -> recompile every child template, which extends _parent.volt
Temporarily workaround: deploy script should clean cache dir
You need to set up to volt using 'compileAlways' => true as mentioned in the documentation:
By default, and for performance reasons, Volt only checks for changes in the children templates to know when to re-compile them to plain PHP again, so it is recommended initialize Volt with the option ‘compileAlways’ => true. Thus, the templates are compiled always taking into account changes in the parent templates.
http://docs.phalconphp.com/en/latest/reference/volt.html#template-inheritance
Thanks. But "‘compileAlways’ => true" means every template will be compiled on any request. It seems it's just a fast workaround and the way into bad perfomance.
Are there plans to improve Volt to check changes of parent template with "‘compileAlways’ => false" ?
The idea is using "‘compileAlways’ => true" only in development then you can change it to false also set up "stat" => false providing better performance
Hmmm... On one hand you wrote "set it into 'true' for use Volt's inharitance feature", on other "set it into 'false', for better perfomance".
The issue is that I should manualy/by-shell-script clean the cache while making deploy with "‘compileAlways’ => false".
Why does the Volt engine not checking changes of a parent template with "‘compileAlways’ => false" ? Is it so expansive to check if parent is up-to-date ?
Today we only perform a stat on both compiled file and child template. If the modification time of the compiled file is recent than the one in the child template Volt serves the compiled file. The overhead is minimum there.
But if we check for changes on the parent we would need:
- Parse the child template checking for an 'extends' statement
- Parse the parent template to check if it's already extended
- Do step 2 until the parent templates aren't extended
So there is no way to see if the parent (or its parents) has changed without parsing all the templates to check if they are extended (contains a {% extends %})
Then it seems there is only way to use Volt Temlate inheritance in production: clean cache by deployment script.
As for me, such behavior means architectural issue. You can cache timestamps for inheritance tree and do not parse templates for {% extends %} every time. Then your 1) 2) 3) should be replaced by only get list of templates from cache, check their timestamps. In any case you already have list of templates for different render levels. Extend it with dependences and ... that's all =) . I think it is inevitable as a rise of the Sun.
The list of templates also can be outdated with respect to the templates, note that multiple inheritance is allowed.
a.volt
<html>{%block hello %}{% endblock %}{%block bye %}{% endblock %}</html>
b.volt:
{% extends "a.volt"}
{%block hello %}hello{% endblock %}
c.volt:
{% extends "b.volt"}
{%block bye %}bye{% endblock %}
If you compile c.volt, instead of checking whether it's compiled template is older than c.volt itself, it would need to parse completely c.volt, realize that it's extended, parse b.volt, same thing, realize that it's extended, parse a.volt realizing that is not extended. So all this parsing stuff is what actually is avoided when compileAlways is off. You can set up compileAlways => "on" in development and once your application is on production change it to compileAlways => "off" to avoid the overhead of compile the templates every time.