src/Cache/CacheClearSubscriber.php line 28

Open in your IDE?
  1. <?php
  2. namespace App\Cache;
  3. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  4. use Symfony\Component\Console\Event\ConsoleCommandEvent;
  5. use App\Cache\CustomResultCache;
  6. /*
  7.  * Clear cached keys when doctrine clear result cache command is executed
  8.  */
  9. class CacheClearSubscriber implements EventSubscriberInterface
  10. {
  11.     private $customResultCache;
  12.     public function __construct(CustomResultCache $customResultCache)
  13.     {
  14.         $this->customResultCache $customResultCache;
  15.     }
  16.     public static function getSubscribedEvents()
  17.     {
  18.         return [
  19.             ConsoleCommandEvent::class => 'onConsoleCommand',
  20.         ];
  21.     }
  22.     public function onConsoleCommand(ConsoleCommandEvent $event)
  23.     {
  24.         if($event->getCommand()->getName() === 'doctrine:cache:clear-result')
  25.         {
  26.             $this->customResultCache->clear();
  27.         }
  28.     }
  29. }