Cache #530
Replies: 1 comment
-
Hi @Bombastisk, Thank you for your question. It is not currently possible to disable There are two levels of cache: the low-level one and the high-level one. The low-level cache is the one you are talking about - the internal cache of the environment. The high-level caches are provided by The low-level cache is expected to live as long as the time needed for the template to be compiled and executed. The low-level cache is extremely important for performance: it is in-memory, so it is the fastest possible cache at our disposal, but more importantly it is used to cache the sub-templates that the template we are compiling depends on. Let's take the following template {% for i in 1..10 %}
{{ include('partial.htlm.twig') }}
{% endfor %} When that template is executed, the Basically, the low-level cache serves this only purpose: speeding the compilation of a template by caching the result of the compilation of all the templates it depends on, in case they need to be reused. The high-level cache steps in when Twing needs to compile a template - in other words when it did not find it already in the low-level cache. In the case of our example, the high-level cache would only be used on the first iteration. The high-level cache will check if a compiled template exists for the path In a nutshell:
The issue that may arise with the low-level cache is that if you plan to reuse an environment multiple times, you will hit the low-level cache all the time even if It means that, would you reuse the same environment for subsequent compilation, you would certainly not get the expected result if one of the included templates did change. That's why you should always create a fresh environment, whenever you need to compile a template. The low-level cache would then be empty and the high-level cache would provide freshness support, ensuring that a file that has been modified isn't served. |
Beta Was this translation helpful? Give feedback.
-
I have checked out the Twing project. Quite nice! I have one question though. Is there any way to completely turn off internal caching for the templates. So that they are loaded from scratch every time?
Beta Was this translation helpful? Give feedback.
All reactions