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) fasterTomasz Madeyski– Tomasz Madeyski2015-09-04 11:37:35 +00:00Commented Sep 4, 2015 at 11:37
- Because in my server this cache covers lot of spaceKaran Kumar– Karan Kumar2015-09-04 11:40:26 +00:00Commented Sep 4, 2015 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 modeTomasz Madeyski– Tomasz Madeyski2015-09-04 11:44:04 +00:00Commented Sep 4, 2015 at 11:44
- 1Without cache every request would take over a second to complete. Disk space is cheap.Gerry– Gerry2015-09-04 11:47:21 +00:00Commented Sep 4, 2015 at 11:47
- setting your app in debug mode: how ?Karan Kumar– Karan Kumar2015-09-04 11:49:47 +00:00Commented Sep 4, 2015 at 11:49
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 1 Comment
//$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!!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(); Comments
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.
Comments
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.
1 Comment
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 Comment
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); } } 2 Comments
APP_ENV or possibly some other env var dedicated to turning cache on/off to avoid possibly doing this in a production env.