merged branch jalliot/load-class-cache (PR #4542)
Commits -------f09789b
[FrameworkBundle] Generate the class cache when warming up the cache Discussion ---------- [FrameworkBundle] Generate the class cache when warming up the cache Bug fix: no Feature addition: yes Backwards compatibility break: no Symfony2 tests pass: [![Build Status](https://secure.travis-ci.org/jalliot/symfony.png?branch=load-class-cache)](http://travis-ci.org/jalliot/symfony) Fixes the following tickets: - Todo: - With this PR, the commands `cache:clear` (if `--no-warmup` hasn't been specified) and `cache:warmup` generate the class cache. Now the first page load after clearing the cache does not take over one second anymore :) Of course, if someone does not want to use the class cache for whatever reason, he can always remove the `$kernel->loadClassCache()` in his front controller and the cache will just be ignored... On a side note, can someone explain why [SensioDistributionBundle does not warmup the cache in the Composer post-install script](https://github.com/sensio/SensioDistributionBundle/blob/master/Composer/ScriptHandler.php#L48)? --------------------------------------------------------------------------- by travisbot at 2012-06-10T05:18:30Z This pull request [passes](http://travis-ci.org/symfony/symfony/builds/1579114) (merged baecbaee into6266b72d
). --------------------------------------------------------------------------- by travisbot at 2012-06-10T05:24:48Z This pull request [passes](http://travis-ci.org/symfony/symfony/builds/1579154) (mergedf09789b1
into6266b72d
). --------------------------------------------------------------------------- by jalliot at 2012-06-28T23:18:54Z @fabpot ping
This commit is contained in:
commit
7ac10fefa0
@ -34,3 +34,5 @@ CHANGELOG
|
||||
declares how long a cookie can be stored on the remote client.
|
||||
* Removed 'auto_start' configuration parameter from session config. The session will
|
||||
start on demand.
|
||||
* Commands cache:warmup and cache:clear (unless --no-warmup is specified) now
|
||||
create the class cache.
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
namespace Symfony\Bundle\FrameworkBundle\Command;
|
||||
|
||||
use Symfony\Component\ClassLoader\ClassCollectionLoader;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
@ -63,7 +64,8 @@ EOF
|
||||
}
|
||||
|
||||
$kernel = $this->getContainer()->get('kernel');
|
||||
$output->writeln(sprintf('Clearing the cache for the <info>%s</info> environment with debug <info>%s</info>', $kernel->getEnvironment(), var_export($kernel->isDebug(), true)));
|
||||
$debug = $kernel->isDebug();
|
||||
$output->writeln(sprintf('Clearing the cache for the <info>%s</info> environment with debug <info>%s</info>', $kernel->getEnvironment(), var_export($debug, true)));
|
||||
|
||||
$this->getContainer()->get('cache_clearer')->clear($realCacheDir);
|
||||
|
||||
@ -76,11 +78,21 @@ EOF
|
||||
|
||||
rename($realCacheDir, $oldCacheDir);
|
||||
rename($warmupDir, $realCacheDir);
|
||||
|
||||
$this->createClassCache($realCacheDir, $debug);
|
||||
}
|
||||
|
||||
$this->getContainer()->get('filesystem')->remove($oldCacheDir);
|
||||
}
|
||||
|
||||
protected function createClassCache($cacheDir, $debug)
|
||||
{
|
||||
$classmap = $cacheDir.'/classes.map';
|
||||
if (is_file($classmap)) {
|
||||
ClassCollectionLoader::load(include($classmap), $cacheDir, 'classes', $debug, false, '.php');
|
||||
}
|
||||
}
|
||||
|
||||
protected function warmup($warmupDir, $enableOptionalWarmers = true)
|
||||
{
|
||||
$this->getContainer()->get('filesystem')->remove($warmupDir);
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
namespace Symfony\Bundle\FrameworkBundle\Command;
|
||||
|
||||
use Symfony\Component\ClassLoader\ClassCollectionLoader;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
@ -56,6 +57,12 @@ EOF
|
||||
$warmer->enableOptionalWarmers();
|
||||
}
|
||||
|
||||
$warmer->warmUp($this->getContainer()->getParameter('kernel.cache_dir'));
|
||||
$cacheDir = $this->getContainer()->getParameter('kernel.cache_dir');
|
||||
$warmer->warmUp($cacheDir);
|
||||
|
||||
$classmap = $cacheDir.'/classes.map';
|
||||
if (is_file($classmap)) {
|
||||
ClassCollectionLoader::load(include($classmap), $cacheDir, 'classes', $kernel->isDebug(), false, '.php');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user