php 如何在 symfony 中禁用缓存
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32397149/
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
How to disable cache in symfony
提问by Karan Kumar
I am developing a website in symfony framework. In my cache folder a huge cache is stored. I want to disable cache permanently.
我正在 symfony 框架中开发一个网站。在我的缓存文件夹中存储了一个巨大的缓存。我想永久禁用缓存。
回答by Diego Ferri
While I advise against disabling the cache on a production system, you can disable the twig templating engine cache, by editing and adding to your config.yml
file
虽然我建议不要在生产系统上禁用缓存,但您可以通过编辑和添加到config.yml
文件来禁用树枝模板引擎缓存
twig:
cache: false
回答by StampyCode
The class cache in Symfony2 can be disabled in you app.php
or app_dev.php
file:
Symfony2 中的类缓存可以在您app.php
或app_dev.php
文件中禁用:
$loader = require_once __DIR__.'/../app/autoload.php';
Debug::enable();
$kernel = new AppKernel('dev', true);
#$kernel->loadClassCache(); // <-- comment out this line
$request = Request::createFromGlobals();
回答by Manuel Pancorbo
I think you can't disable "permanently cache", since Symfony applications use some cached files in order to run faster (or simply to run). Examples of this are the files that contains the dependency injection container (appProdProjectContainer.php).
我认为你不能禁用“永久缓存”,因为 Symfony 应用程序使用一些缓存文件来运行得更快(或只是为了运行)。这方面的示例是包含依赖项注入容器 (appProdProjectContainer.php) 的文件。
You can disable some types of cache like Twig cache (as Diego Ferri said before) or Http Cache (unwrapping AppKernel with AppCache in app.php) or even Doctrine cache (in config.yml).
您可以禁用某些类型的缓存,如 Twig 缓存(如 Diego Ferri 之前所说)或 Http 缓存(在 app.php 中使用 AppCache 解包 AppKernel)甚至 Doctrine 缓存(在 config.yml 中)。
However I would not recommend this. The more you cache the app, the faster your app will be.
但是我不会推荐这个。您缓存的应用程序越多,您的应用程序就会越快。
回答by Dedicated Manager
I was having caching issues even when using app_dev.php. I would change a route but it wouldn't update when I tried accessing it via a browser.
即使在使用 app_dev.php 时我也遇到缓存问题。我会更改路线,但是当我尝试通过浏览器访问它时它不会更新。
I tried commenting out the anything that had cache in it (as stated above). My AppKernel('dev', true) was set to true. Nothing worked.
我尝试注释掉其中包含缓存的任何内容(如上所述)。我的 AppKernel('dev', true) 设置为 true。没有任何效果。
If I ran the console cache:clear it would fix it, but the next routing change would break again. I had to run cache:clear with every save, which was ridiculous.
如果我运行控制台缓存:清除它会修复它,但下一个路由更改会再次中断。我不得不在每次保存时运行缓存:清除,这很荒谬。
My issue turned out that because I was working remotely over SFTP, PHP Storm (my editor) was "preserving timestamp" in its deployment configuration. Once I changed that configuration the issues went away. Apparently there is some caching going on that is looking at the file timestamps, even in the dev environment.
我的问题原来是因为我通过 SFTP 远程工作,所以 PHP Storm(我的编辑器)在其部署配置中“保留时间戳”。一旦我更改了该配置,问题就消失了。显然,即使在开发环境中,也有一些缓存正在查看文件时间戳。
回答by Michael Emerson
When you are working in a dev environment state, the cache is disabled anyway - I'm assuming you only want to have it disabled within development, so use the /app_dev.php file to make sure nothing is cached.
当您在开发环境状态下工作时,无论如何都会禁用缓存 - 我假设您只想在开发中禁用它,因此请使用 /app_dev.php 文件确保没有缓存任何内容。
Alternatively you can empty the cache periodically on the command line using
或者,您可以使用命令行定期清空缓存
php app/console cache:clear
You can see all the different parameters here: http://symfony.com/doc/current/cookbook/console/usage.html
你可以在这里看到所有不同的参数:http: //symfony.com/doc/current/cookbook/console/usage.html