I'd like to know how to handle and check cache variants I'm creating.
Let's say I have a project and add ...
<a href="#">Logout {{ app.user }}</a>
... to the head of every page. In this case app.user it is a part of fos_user_bundle.
For every user the page would have a different content (the user name). So the number of cache variants would instantly multiply by the number of users.
Before: 100 Pages, 100 Cache variants
After: 100 Pages * 500 Users = 50.000 Cache variants
Will symfony2 create cache variants for each end every user? Where is this controlled?
I know that I can work with edge side includes (ESI). Do I have to do it here in order to prevent producing variants?
Where can I see and check the number of cache variants I'm producing?
Thanks for your help.
Twig is parsed to executable code which is stored in app/cache/dev or app/cache/prod folder. If you inject a variable into twig file then it is delivered to PHP file as simple variable, so you can provide application with thousands of users and it will not affect the number of variants.
For example, if you have twig with line like this:
<a href="#">Logout {{ app.user }}</a>
it's parsed to something like:
<a href="#">Logout <?php echo $app->getUser() ?> </a>
so there is only one variant.
In fact the cache is more complicated than this, but the concept is the same.
You can check it yourself in app/cache/* directories.