What is the best way to clean the cache without running the console command?
You can call this action to clear a cache:
/** * @Route("/cache/clear", name="adyax_cache_clear") */ public function cacheClearAction(Request $request) { $input = new \Symfony\Component\Console\Input\ArgvInput(array('console','cache:clear')); $application = new \Symfony\Bundle\FrameworkBundle\Console\Application($this->get('kernel')); $application->run($input); }
Most recent best way (2017). I'm creating this in controller:
use Symfony\Component\Console\Input\ArrayInput;use Symfony\Bundle\FrameworkBundle\Console\Application;use Symfony\Component\Console\Output\BufferedOutput;/** * Refresh Cache */public function refreshRoutes(){ $kernel = $this->container->get('kernel'); $application = new Application($kernel); $application->setAutoExit(false); $input = new ArrayInput([ 'command' => 'cache:clear', '--env' => 'prod', ]); $output = new BufferedOutput(); $application->run($input, $output);}