merged branch jmikola/cc-optional-warmers (PR #3302)

Commits
-------

42c9892 [FrameworkBundle] Allow cache:clear/warmup to skip optional warmers

Discussion
----------

[FrameworkBundle] Allow cache:clear/warmup to skip optional warmers

> Bug fix: no
> Feature addition: yes
> Backwards compatibility break: yes
> Symfony2 tests pass: [yes](http://travis-ci.org/#!/jmikola/symfony/builds/647861)

Exercise.com has been using this for a while for our local environments. Skipping the optional cache warmers (namely Assetic) can save quite a bit of time.
This commit is contained in:
Fabien Potencier 2012-02-09 07:08:52 +01:00
commit 4c4a1d6d8a
2 changed files with 17 additions and 4 deletions

View File

@ -36,6 +36,7 @@ class CacheClearCommand extends ContainerAwareCommand
->setName('cache:clear')
->setDefinition(array(
new InputOption('no-warmup', '', InputOption::VALUE_NONE, 'Do not warm up the cache'),
new InputOption('no-optional-warmers', '', InputOption::VALUE_NONE, 'Skip optional cache warmers (faster)'),
))
->setDescription('Clears the cache')
->setHelp(<<<EOF
@ -71,7 +72,7 @@ EOF
} else {
$warmupDir = $realCacheDir.'_new';
$this->warmup($warmupDir);
$this->warmup($warmupDir, !$input->getOption('no-optional-warmers'));
rename($realCacheDir, $oldCacheDir);
rename($warmupDir, $realCacheDir);
@ -80,7 +81,7 @@ EOF
$this->getContainer()->get('filesystem')->remove($oldCacheDir);
}
protected function warmup($warmupDir)
protected function warmup($warmupDir, $enableOptionalWarmers = true)
{
$this->getContainer()->get('filesystem')->remove($warmupDir);
@ -96,7 +97,11 @@ EOF
$kernel->boot();
$warmer = $kernel->getContainer()->get('cache_warmer');
$warmer->enableOptionalWarmers();
if ($enableOptionalWarmers) {
$warmer->enableOptionalWarmers();
}
$warmer->warmUp($warmupDir);
// fix container files and classes

View File

@ -12,6 +12,7 @@
namespace Symfony\Bundle\FrameworkBundle\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
/**
@ -28,6 +29,9 @@ class CacheWarmupCommand extends ContainerAwareCommand
{
$this
->setName('cache:warmup')
->setDefinition(array(
new InputOption('no-optional-warmers', '', InputOption::VALUE_NONE, 'Skip optional cache warmers (faster)'),
))
->setDescription('Warms up an empty cache')
->setHelp(<<<EOF
The <info>cache:warmup</info> command warms up the cache.
@ -47,7 +51,11 @@ EOF
$output->writeln(sprintf('Warming up the cache for the <info>%s</info> environment with debug <info>%s</info>', $kernel->getEnvironment(), var_export($kernel->isDebug(), true)));
$warmer = $this->getContainer()->get('cache_warmer');
$warmer->enableOptionalWarmers();
if (!$input->getOption('no-optional-warmers')) {
$warmer->enableOptionalWarmers();
}
$warmer->warmUp($this->getContainer()->getParameter('kernel.cache_dir'));
}
}