38

Is there a way to disable the caching function in Symfony2? I tried to find the setting in the config* and parameters.ini files and I searched a lot. Ok, I found a few solutions, but nothing for the latest version (Symfony2).

WHY? Because I want to test new templates and functions without clearing the app/cache* all the time.

NaN
  • 3,501
  • 8
  • 44
  • 77
  • this cacheing concept is still confusing me. not sure if it is possible. there are two caches actually - at least - for boostrapping (twig, config, routes) and another for the used components. not sure if, given the architecture of the sf2 std distrib, the idea of disabling caches makes sense at all. :-/ the code would have to be considerably changed I guess, cause you would have to translate the yml-configs, yml-routings and templates to php ... maybe its easier to become cache-independant if one uses php for routes, templates and configs in the first place. – Raffael Aug 25 '11 at 14:53
  • 1
    What kind/level of cache do you want to disable? For HTTP cacheing, the best overview is probably [here](http://symfony.com/doc/current/book/http_cache.html) -- note it's not turned on by default anyway, though. Can you maybe explain in a bit more detail what problem you're trying to solve? – Matt Gibson Aug 25 '11 at 14:54
  • 1
    I want to test templates and the configuration without clearing the /app/cache/* all time. – NaN Aug 26 '11 at 09:09
  • 2
    Test using app_dev.php :) – M. Foti Oct 01 '13 at 14:15

5 Answers5

73

I'm assuming you're using the Twig engine, (the default templating engine for Symfony2). To disable caching in twig, so that you do not have to keep clearing the cache like so:

rm -rf app/cache/*

Navigate to your app config file (by defualt will be located in ../app/config/config.yml from your root directory). Scroll to the twig configuration settings (under twig:) and change the cache value (which should be pointing to the cache directory) to false like so:

twig:
    cache:  false

If you do not see any cache configuration entry, simply add the line above.

It may also be helpful to checkout the configuring reference for the Twig bundle: http://symfony.com/doc/2.0/reference/configuration/twig.html

After editing your config_dev.yml file, go to your terminal and run:

app/console cache:clear
dohpaz42
  • 520
  • 4
  • 18
Prince Mabandla
  • 996
  • 7
  • 4
  • Hi All, i tried the provided solution and all i get now from twig is a blank page. i never had the cache option in my yml file. Anyone has an idea .. ? – xeon Mar 15 '13 at 12:19
  • 2
    I recommend disabling the twig cache on `app_dev.php` only. It works fine and stays away from your production configuration. – Plínio César Dec 15 '13 at 14:46
  • 1
    How do you disable twig cache in app_dev.php? All of the documentation say that app_dev.php by default disables twig cache, but im not seeing this behavior. – jhnlsn Jan 02 '14 at 21:04
  • Saved hours of my time doing this instead of cache:clear everytime I make change to a template! – AyB Jul 12 '16 at 13:38
  • you mention both config.yml and config_dev.yml. Do both need to be modified? – Mike W Feb 23 '17 at 22:57
8

Okay, regarding your clarification the solution simply is to use the dev-environment through the front-controller web/app_dev.php. Then sf2 keeps track of your adjustments and you don't have to clear the cache.

Raffael
  • 19,547
  • 15
  • 82
  • 160
5

This original solution works for me http://symfony.com/doc/current/cookbook/debugging.html

Dmitry Sobolev
  • 927
  • 15
  • 18
5

In addition to the accepted answer, I propose to edit your config_dev.yml in a way so it still debugs your twig template. To do so, add this code to your config_dev.yml file:

twig:
    cache: false
    debug: true

services:
    twig.extension.debug:
        class: Twig_Extension_Debug
        tags:
                - { name: 'twig.extension' }

After editing your config_dev.yml file, go to your terminal and run:

app/console cache:clear

By doing so, you will reload your config_dev.yml settings - make your project run with the new configuration.

Hope this helps.

Antoine
  • 800
  • 3
  • 14
  • 29
DevWL
  • 17,345
  • 6
  • 90
  • 86
4

Edit 'config_dev.yml' and 'config.yml' and then put in both

twig:
    cache:  false
albert
  • 1,766
  • 1
  • 21
  • 24