Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How reload Twig cache in Symfony 2

Tags:

php

twig

symfony

I have a application which is developed in PHP using the Symfony 2 framework. I have changed a HTML file, but the change is not reflecting when I refresh the page.

  1. I restarted the server. No luck.

  2. I tried to remove the Twig folder from the /protected/cache/ page itself. This is not loading.

How can I reload the Twig cache?

Notes:

  • I am using tomcat server to deploy.
  • I don’t have the Symfony 2 command line configured on the server.
  • I am new to PHP.
like image 922
Azhar Avatar asked May 05 '13 17:05

Azhar


2 Answers

The most simple way, type the command :

rm -rf app/cache/* 

The point is: all files in app/cache/ can be removed freely, they are regenerated when needed.

If you really want to clear only twig cache :

rm -rf app/cache/<environment>/twig 

Replace <environment> by dev, prod, or test according to your requirements.

like image 93
Alain Tiemblo Avatar answered Sep 22 '22 19:09

Alain Tiemblo


When creating a new Twig_Environment instance, you can pass an array of options as the constructor second argument. One of them is auto_reload. When developing with Twig, it's useful to recompile the template whenever the source code changes. If you don't provide a value for the auto_reload option, it will be determined automatically based on the debug value.

Set auto_reload to be true:

$twig = new Twig_Environment($loader, array('auto_reload' => true)); 

Twig's documentation for developers: http://twig.sensiolabs.org/doc/api.html#environment-options

like image 37
Link Avatar answered Sep 25 '22 19:09

Link