CachePoolClearerCacheWarmer.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Bundle\FrameworkBundle\CacheWarmer;
  11. use Symfony\Component\HttpKernel\CacheClearer\Psr6CacheClearer;
  12. use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
  13. /**
  14. * Clears the cache pools when warming up the cache.
  15. *
  16. * Do not use in production!
  17. *
  18. * @author Teoh Han Hui <teohhanhui@gmail.com>
  19. *
  20. * @internal
  21. */
  22. final class CachePoolClearerCacheWarmer implements CacheWarmerInterface
  23. {
  24. private $poolClearer;
  25. private $pools;
  26. public function __construct(Psr6CacheClearer $poolClearer, array $pools = [])
  27. {
  28. $this->poolClearer = $poolClearer;
  29. $this->pools = $pools;
  30. }
  31. /**
  32. * {@inheritdoc}
  33. *
  34. * @return string[]
  35. */
  36. public function warmUp($cacheDirectory): array
  37. {
  38. foreach ($this->pools as $pool) {
  39. if ($this->poolClearer->hasPool($pool)) {
  40. $this->poolClearer->clearPool($pool);
  41. }
  42. }
  43. return [];
  44. }
  45. /**
  46. * {@inheritdoc}
  47. */
  48. public function isOptional(): bool
  49. {
  50. // optional cache warmers are not run when handling the request
  51. return false;
  52. }
  53. }