Skip to content

Instantly share code, notes, and snippets.

@jwage
Last active July 22, 2018 13:38
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jwage/000b294ac00799ea684d to your computer and use it in GitHub Desktop.
Save jwage/000b294ac00799ea684d to your computer and use it in GitHub Desktop.
<?php
namespace App\Component\HttpKernel\CacheWarmer;
use Spork\Batch\Strategy\ChunkStrategy;
use Spork\ProcessManager;
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerAggregate;
class SporkCacheWarmerAggregate extends CacheWarmerAggregate
{
protected $chunks = 10;
/**
* Warms up the cache.
*
* @param string $cacheDir The cache directory
*/
public function warmUp($cacheDir)
{
$spork = new ProcessManager();
$warmers = array();
foreach ($this->warmers as $warmer) {
if (!$this->optionalsEnabled && $warmer->isOptional()) {
continue;
}
$warmers[] = $warmer;
}
$batch = $spork->createBatchJob(
$warmers,
new ChunkStrategy($this->chunks)
);
$batch->execute(function ($warmer) use ($cacheDir) {
$warmer->warmUp($cacheDir);
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment