php Symfony2 禁用缓存?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7192357/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 02:14:09  来源:igfitidea点击:

Symfony2 disable cache?

phpmodel-view-controllercachingframeworkssymfony

提问by NaN

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).

有没有办法在 Symfony2 中禁用缓存功能?我试图在 config* 和 parameters.ini 文件中找到设置,并进行了大量搜索。好的,我找到了一些解决方案,但对于最新版本(Symfony2)没有任何解决方案。

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

为什么?因为我想在不清除应用程序/缓存* 的情况下测试新模板和功能。

回答by Prince Mabandla

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:

我假设您使用的是 Twig 引擎(Symfony2 的默认模板引擎)。在 Twig 中禁用缓存,这样您就不必像这样继续清除缓存:

rm -rf app/cache/*

Navigate to your app config file (by defualt will be located in ../app/config/config.ymlfrom 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 falselike so:

导航到您的应用程序配置文件(默认将位于根目录中的../app/config/config.yml 中)。滚动到 twig 配置设置(在twig: 下)并将缓存值(应该指向缓存目录)更改为false,如下所示:

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

查看 Twig 包的配置参考也可能会有所帮助:http: //symfony.com/doc/2.0/reference/configuration/twig.html

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

编辑 config_dev.yml 文件后,转到终端并运行:

app/console cache:clear

回答by Raffael

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.

好的,关于您的澄清,解决方案只是通过前端控制器 web/app_dev.php 使用开发环境。然后 sf2 会跟踪您的调整,您不必清除缓存。

回答by Dmitry Sobolev

回答by DevWL

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:

除了接受的答案之外,我还建议以某种方式编辑您的 config_dev.yml,以便它仍然可以调试您的树枝模板。为此,请将此代码添加到您的 config_dev.yml 文件中:

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:

编辑 config_dev.yml 文件后,转到终端并运行:

app/console cache:clear

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

通过这样做,您将重新加载 config_dev.yml 设置 - 使您的项目使用新配置运行。

Hope this helps.

希望这可以帮助。

回答by albert

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

编辑“config_dev.yml”和“config.yml”,然后放入

twig:
    cache:  false