Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How the twig caching exactly work? [closed]

Tags:

php

twig

I have recently start work with twig in my project, I have check that twig have create cache folder, and check that twig basically create some php classes for cache,

I want to understand exactly how this mechanism is work, how it beneficial to reduce the page loading time, any one can help me ?

like image 972
Saiyam Patel Avatar asked Aug 05 '14 03:08

Saiyam Patel


1 Answers

Twig evaluation process looks like:

  1. Your templates are parsed, abstract syntax tree (AST) is built from then and then AST is transformed into php code
  2. Php code from the step #1 is evaluated

With Twig templates caching you eliminate step #1, since the transformation results are written to a cache files.

So it is highly recommended to use it on production. Just make sure you clear the template directory cache on deploy or specify another directory as a target. It could be a good idea to include the application version number in the path.

like image 108
zerkms Avatar answered Sep 20 '22 07:09

zerkms