Symfony2 - to see changes in a branch, you need to clear the cache every time

I only have this problem. Every time I make changes in my branch, I have to cache:clear . and also errors are not displayed if something is wrong in the code? What should I do?!

+4
source share
2 answers

I have encountered this problem several times. If your site is accessing a large number of users, and you clear the cache. I am sure that your website did not work for a couple of minutes until a new cache was generated.

Thus, a clear cache on a production server does not have to be regular. There are several solutions or tricks to solve this problem:

  • Find the time when your site has low traffic. Maybe someday at night, and then clear the cache.
  • When you want to clear the cache, set up a replica of the production server, then plan to switch the public domain IP address to a new replica for synchronization so that the user cannot survive downtime and as soon as you clear the server’s cache. Switch the public IP address to the production server.
  • if you make some changes to the ietwig templates and want to make changes in the life of the workplace. Then try to find the templates in the app / cache / prod / twig directory and grep the name of the template, and you will get files, than move files or delete files, and your changes will live on the working server.

how to clear cache

 php app/console cache:clear chmod -R 777 app/cache chmod -R 777 app/logs 

Alternative

You need to make some changes to the app.php file located in the web folder.

change

  $kernel = new AppKernel('prod', false); 

to

  $kernel = new AppKernel('prod', true); 

and clear the cache

+6
source

I just created a console command to selectively list or delete twig cache files manually, instead of running a multiple clearing cache that clears everything. Syntax:

kmlf: twig --clear --env = dev AcmeBundle :: nglayout.html.twig AcmeBundle: Simple: simple3.html.twig

you can exclude the --clear flag if you just want to specify the location of the cache files. It seems to work well in both the prod and dev environment for Symfony 2.3:

 use Symfony\Component\Console\Command\Command; use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\Output; class TwigCacheCommand extends ContainerAwareCommand { public function configure() { $this->setName('kmlf:twig') ->setDescription('selectively manage the twig cache') ->addArgument( 'names', InputArgument::IS_ARRAY, 'Example AcmeBundle:Section:view.html.twig', null )->addOption('clear','c', InputOption::VALUE_NONE, 'delete cache files' ); } public function write($output, $text) { $output->writeln($text); } public function execute(InputInterface $input, OutputInterface $output) { $environment = $this->getContainer()->get('twig'); $names = $input->getArgument('names'); $actionName = null; if ($input->getOption('clear')) { $actionName = 'deleting'; $action = function ($fileName) { unlink($fileName); }; } else { $actionName="path:"; $action = function ($filename) { }; } foreach ($names as $name) { $fileName = $environment->getCacheFilename($name); if (file_exists($fileName)) { $action($fileName); } else { $fileName = 'not found.'; } $this->write($output, $actionName.' '.$name."\ncacheFile: ".$fileName); } $this->write($output, 'Done'); } } 
+3
source

Source: https://habr.com/ru/post/1490250/


All Articles