Skip to content

Commit

Permalink
feature #16263 [FrameworkBundle] Add a new ClassCache cache warmer (t…
Browse files Browse the repository at this point in the history
…ucksaun)

This PR was merged into the 2.8 branch.

Discussion
----------

[FrameworkBundle] Add a new ClassCache cache warmer

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

This new cache warmer allows to remove the known slowness of the first hit of a Symfony application (even when cache has been warmed up). This also allows to make a Symfony application runnable on a read-only filesystem (like in a Docker container for example)

Commits
-------

b570d6c [FrameworkBundle] Add a new ClassCache cache warmer
  • Loading branch information
fabpot committed Oct 19, 2015
2 parents b9c0fe4 + b570d6c commit 43026f9
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
@@ -0,0 +1,49 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Bundle\FrameworkBundle\CacheWarmer;

use Symfony\Component\ClassLoader\ClassCollectionLoader;
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;

/**
* Generates the Class Cache (classes.php) file.
*
* @author Tugdual Saunier <tucksaun@gmail.com>
*/
class ClassCacheCacheWarmer implements CacheWarmerInterface
{
/**
* Warms up the cache.
*
* @param string $cacheDir The cache directory
*/
public function warmUp($cacheDir)
{
$classmap = $cacheDir.'/classes.map';

if (!is_file($classmap)) {
return;
}

ClassCollectionLoader::load(include($classmap), $cacheDir, 'classes', false);
}

/**
* Checks whether this warmer is optional or not.
*
* @return bool always true
*/
public function isOptional()
{
return true;
}
}
Expand Up @@ -34,6 +34,10 @@
<argument type="collection" />
</service>

<service id="kernel.class_cache.cache_warmer" class="Symfony\Bundle\FrameworkBundle\CacheWarmer\ClassCacheCacheWarmer">
<tag name="kernel.cache_warmer" />
</service>

<service id="cache_clearer" class="%cache_clearer.class%">
<argument type="collection" />
</service>
Expand Down

0 comments on commit 43026f9

Please sign in to comment.