10

I am developing a website in symfony framework. In my cache folder a huge cache is stored. I want to disable cache permanently.

7
  • 2
    why would you want to disable cache? - it makes your website (much) faster Commented Sep 4, 2015 at 11:37
  • Because in my server this cache covers lot of space Commented Sep 4, 2015 at 11:40
  • 1
    I 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 Commented Sep 4, 2015 at 11:44
  • 1
    Without cache every request would take over a second to complete. Disk space is cheap. Commented Sep 4, 2015 at 11:47
  • setting your app in debug mode: how ? Commented Sep 4, 2015 at 11:49

6 Answers 6

17

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 
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks 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!!
8

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(); 

Symfony2 - Disabling the Bootstrap File and Class Caching

Comments

6

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

2

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

correct - symfony relies on caching - some cache (like the classesArray) is rebuild every request, when it is deleted.
0

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

caching is not disabled in dev mode afaik.
0

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

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.
yes of course some of the control in the .env should be added, this is just an example how do do it roughly

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.