I'm wanting to invalidate/clear the cache of all child templates (or completely recompile everything) when a change occurs on the parent layout template. I am aware of the Volt setting "compileAlways" => true
but I'm looking for a solution that can be used in a production environment and isn't susceptible to race conditions. I'll provide some example templates below and attempt to clearly explain the problem at hand.
{# main.volt #}
<!DOCTYPE html>
<html>
<head>
<title>Title</title>
</head>
<body>
{% block content %}{% endblock %}
</body>
</html>
{# layout.volt #}
{% extends "main.volt" %}
{% block content %}
<h1>Table of contents</h1>
{% endblock %}
{# child.volt #}
{% extends "main.volt" %}
{% block content %}
<h1>Table of contents</h1>
{% endblock %}
/view/layout/main.volt
/view/layout/layout.volt
/view/project1/child.volt
/view/project2/child.volt
/view/project3/child.volt
/view/project4/child.volt
/view/project5/child.volt
...
Given the templates above, lets assume we have hundreds of child templates that extend layout.volt
and all templates have been compiled and cached. The problem is that updating the layout.volt
or base.volt
templates will have no effect on the hundreds of child templates extending it. I've been racking my brain trying to come up with a solution, it's difficult because as far as I can tell, during compilation & caching no information relating the child template and base template (or vise versa) is ever used in Phalcon.
Lets say the /view/project1/child.volt
template is requested and not cached, during the compilation process at some point the relation between child.volt
, layout.volt
& base.volt
must be known when processing the extends
statement? If it's possible to gather gather that information, then storing it in cache, filenames etc could help determine whether the cache is invalid.
/cache/template.relations.php
return [
'/view/layout/main.volt' => [
'children' => [
'/view/layout/layout.volt',
]
],
'/view/layout/layout.volt' => [
'parent' => '/view/layout/main.volt',
'children' => [
'/view/project1/child.volt',
'/view/project2/child.volt',
'/view/project3/child.volt',
'/view/project4/child.volt',
'/view/project5/child.volt',
]
],
'/view/project1/child.volt' => [
'parent' => '/view/layout/layout.volt',
],
'/view/project2/child.volt' => [
'parent' => '/view/layout/layout.volt',
],
'/view/project3/child.volt' => [
'parent' => '/view/layout/layout.volt',
],
'/view/project4/child.volt' => [
'parent' => '/view/layout/layout.volt',
],
'/view/project5/child.volt' => [
'parent' => '/view/layout/layout.volt',
],
];