Twig caches variable

Hi, I have problem with passing variable into twig. I use $twig->twig_vars to pass variable to twig template, but when I use caching this var is some kind cached also so there are wrong data. When disable chaching or swhitch debugger on, works well and variable is passed properly.

Do you have any suggestins to fix this issue and keep chaching working?


It really depends on when you set those variables. If you set them in an event which only runs when a page is not cached, then it will not work after that page is cached. The caching of Twig itself would not impact this.