带有 if 条件的 Twig 模板缓存

Twig template cache with if condition

我有一个看起来像这样的模板

...
{% if whatever %}
   <div>whatever<div>
{% endif %}
...

我这样设置我的环境

$twig = new \Twig_Environment(
    new \Twig_Loader_Filesystem(
        /template/path/
        ['cache' => '/cache/path/']
    )
);
$whatever = someFunctionFetchingFromDatabase();
$twig->addGlobal('whatever', $whatever);
$twig->render('whatever');

每当 $whatever 变量改变时,编译缓存会重置吗?如果是resetting,那么当模板内部的变量变化很大时,编译缓存有什么意义?

感谢您的热心回答。

我发现编译的 twig 变成了 php 文件,所以所有变量和 if 都保存在编译的 php 文件中。使用带变量的编译很好,不会在每次变量更改时都重新编译。