<?php
namespace App\Cache;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Console\Event\ConsoleCommandEvent;
use App\Cache\CustomResultCache;
/*
* Clear cached keys when doctrine clear result cache command is executed
*/
class CacheClearSubscriber implements EventSubscriberInterface
{
private $customResultCache;
public function __construct(CustomResultCache $customResultCache)
{
$this->customResultCache = $customResultCache;
}
public static function getSubscribedEvents()
{
return [
ConsoleCommandEvent::class => 'onConsoleCommand',
];
}
public function onConsoleCommand(ConsoleCommandEvent $event)
{
if($event->getCommand()->getName() === 'doctrine:cache:clear-result')
{
$this->customResultCache->clear();
}
}
}