Symfony2 disable cache?

58,338

Solution 1

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

Solution 2

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.

Solution 3

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

Solution 4

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.

Solution 5

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

twig:
    cache:  false
Share:
58,338
NaN
Author by

NaN

student@Vienna University of Technology justrocketscience.com

Updated on November 01, 2020

Comments

  • NaN
    NaN over 3 years

    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.

  • xeon
    xeon about 11 years
    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 .. ?
  • Plínio César
    Plínio César over 10 years
    I recommend disabling the twig cache on app_dev.php only. It works fine and stays away from your production configuration.
  • jhnlsn
    jhnlsn over 10 years
    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
    jhnlsn over 10 years
    That link does not show how to set twig to recompile on each request.
  • AyB
    AyB almost 8 years
    Saved hours of my time doing this instead of cache:clear everytime I make change to a template!
  • Mike W
    Mike W about 7 years
    you mention both config.yml and config_dev.yml. Do both need to be modified?