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'); } }
source share