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:
commit
4c4a1d6d8a
@ -36,6 +36,7 @@ class CacheClearCommand extends ContainerAwareCommand
|
|||||||
->setName('cache:clear')
|
->setName('cache:clear')
|
||||||
->setDefinition(array(
|
->setDefinition(array(
|
||||||
new InputOption('no-warmup', '', InputOption::VALUE_NONE, 'Do not warm up the cache'),
|
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')
|
->setDescription('Clears the cache')
|
||||||
->setHelp(<<<EOF
|
->setHelp(<<<EOF
|
||||||
@ -71,7 +72,7 @@ EOF
|
|||||||
} else {
|
} else {
|
||||||
$warmupDir = $realCacheDir.'_new';
|
$warmupDir = $realCacheDir.'_new';
|
||||||
|
|
||||||
$this->warmup($warmupDir);
|
$this->warmup($warmupDir, !$input->getOption('no-optional-warmers'));
|
||||||
|
|
||||||
rename($realCacheDir, $oldCacheDir);
|
rename($realCacheDir, $oldCacheDir);
|
||||||
rename($warmupDir, $realCacheDir);
|
rename($warmupDir, $realCacheDir);
|
||||||
@ -80,7 +81,7 @@ EOF
|
|||||||
$this->getContainer()->get('filesystem')->remove($oldCacheDir);
|
$this->getContainer()->get('filesystem')->remove($oldCacheDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function warmup($warmupDir)
|
protected function warmup($warmupDir, $enableOptionalWarmers = true)
|
||||||
{
|
{
|
||||||
$this->getContainer()->get('filesystem')->remove($warmupDir);
|
$this->getContainer()->get('filesystem')->remove($warmupDir);
|
||||||
|
|
||||||
@ -96,7 +97,11 @@ EOF
|
|||||||
$kernel->boot();
|
$kernel->boot();
|
||||||
|
|
||||||
$warmer = $kernel->getContainer()->get('cache_warmer');
|
$warmer = $kernel->getContainer()->get('cache_warmer');
|
||||||
|
|
||||||
|
if ($enableOptionalWarmers) {
|
||||||
$warmer->enableOptionalWarmers();
|
$warmer->enableOptionalWarmers();
|
||||||
|
}
|
||||||
|
|
||||||
$warmer->warmUp($warmupDir);
|
$warmer->warmUp($warmupDir);
|
||||||
|
|
||||||
// fix container files and classes
|
// fix container files and classes
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
namespace Symfony\Bundle\FrameworkBundle\Command;
|
namespace Symfony\Bundle\FrameworkBundle\Command;
|
||||||
|
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
|
use Symfony\Component\Console\Input\InputOption;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -28,6 +29,9 @@ class CacheWarmupCommand extends ContainerAwareCommand
|
|||||||
{
|
{
|
||||||
$this
|
$this
|
||||||
->setName('cache:warmup')
|
->setName('cache:warmup')
|
||||||
|
->setDefinition(array(
|
||||||
|
new InputOption('no-optional-warmers', '', InputOption::VALUE_NONE, 'Skip optional cache warmers (faster)'),
|
||||||
|
))
|
||||||
->setDescription('Warms up an empty cache')
|
->setDescription('Warms up an empty cache')
|
||||||
->setHelp(<<<EOF
|
->setHelp(<<<EOF
|
||||||
The <info>cache:warmup</info> command warms up the cache.
|
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)));
|
$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 = $this->getContainer()->get('cache_warmer');
|
||||||
|
|
||||||
|
if (!$input->getOption('no-optional-warmers')) {
|
||||||
$warmer->enableOptionalWarmers();
|
$warmer->enableOptionalWarmers();
|
||||||
|
}
|
||||||
|
|
||||||
$warmer->warmUp($this->getContainer()->getParameter('kernel.cache_dir'));
|
$warmer->warmUp($this->getContainer()->getParameter('kernel.cache_dir'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user