I am developing a website in symfony framework. In my cache folder a huge cache is stored. I want to disable cache permanently.
-
2why would you want to disable cache? - it makes your website (much) faster – Tomasz Madeyski Sep 04 '15 at 11:37
-
Because in my server this cache covers lot of space – Karan Kumar Sep 04 '15 at 11:40
-
1I would not recommend this. Disk space is not an issue these days, site performance is. I'm not sure if there is other option to disable the cache than setting your app in debug mode – Tomasz Madeyski Sep 04 '15 at 11:44
-
1Without cache every request would take over a second to complete. Disk space is cheap. – Gerry Sep 04 '15 at 11:47
-
setting your app in debug mode: how ? – Karan Kumar Sep 04 '15 at 11:49
-
And search doesn't exist on SO ? http://stackoverflow.com/questions/7192357/symfony2-disable-cache – w3spi Sep 04 '15 at 11:53
-
As far as I understand caching, your cache is populated once, on `cache:clear --env=prod`. You need to find what is causing cache size explosion. Also, as @TomaszMadeyski pointed out, disk space is rather cheep... – Jovan Perovic Sep 04 '15 at 13:46
6 Answers
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
twig:
cache: false

- 2,657
- 2
- 27
- 35
-
1Thanks for this answer @DiegoFerri. I am using Symfony 2.7.7 and in dev mode it still caching even if I `//$kernel->loadClassCache();` comment out my cache in app_dev.php What I had to do is add in my `config_dev.yml` your snippet and all done!! – George Mylonas Jan 20 '16 at 11:54
The class cache in Symfony2 can be disabled in you app.php
or app_dev.php
file:
$loader = require_once __DIR__.'/../app/autoload.php';
Debug::enable();
$kernel = new AppKernel('dev', true);
#$kernel->loadClassCache(); // <-- comment out this line
$request = Request::createFromGlobals();

- 7,218
- 3
- 28
- 44
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.
I tried commenting out the anything that had cache in it (as stated above). My AppKernel('dev', true) was set to true. Nothing worked.
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.

- 61
- 1
- 1
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).
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).
However I would not recommend this. The more you cache the app, the faster your app will be.

- 29
- 3
-
correct - symfony relies on caching - some cache (like the classesArray) is rebuild every request, when it is deleted. – cklm Oct 22 '16 at 08:36
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.
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

- 1,774
- 4
- 31
- 71
This is from symfony documentation:
https://symfony.com/doc/current/bundles/override.html
If you add a template in a new location, you may need to clear your cache (php bin/console cache:clear), even if you are in debug mode.
That means that the rules how and when the cache is cleared is not even clearly defined in the documentation.
Sometimes you want to change and debug files in vendor folder and after that even this command will not help you:
bin/console cache:clear
The only thing that will help you is to delete all content inside /var/cache/dev folder
A dirty hack for your local environment which you can use to clear cache after each request is:
<?php
namespace App;
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
class Kernel extends BaseKernel
{
use MicroKernelTrait;
public function terminate(Request $request, Response $response)
{
system("rm -rf ".escapeshellarg('../var/cache/dev'));
return parent::terminate($request, $response);
}
}

- 7,931
- 7
- 55
- 89
-
I've never equally hated and loved a solution more in my life. IF one is to go down this route (which is not particularly recommended) It would probably be best to only execute this when in a "debug" or "dev" `APP_ENV` or possibly some other env var dedicated to turning cache on/off to avoid possibly doing this in a production env. – ffgpga08 Jan 27 '23 at 21:44
-
yes of course some of the control in the .env should be added, this is just an example how do do it roughly – fico7489 Jan 27 '23 at 21:51