<?php
namespace App\EventSubscriber;
use App\Services\RequestCacheService;
use EasyCorp\Bundle\EasyAdminBundle\Event\AfterEntityDeletedEvent;
use EasyCorp\Bundle\EasyAdminBundle\Event\AfterEntityPersistedEvent;
use EasyCorp\Bundle\EasyAdminBundle\Event\AfterEntityUpdatedEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class AdminCacheSubscriber implements EventSubscriberInterface {
/**
* @var RequestCacheService
*/
protected $requestCacheService;
/**
* AdminCacheSubscriber constructor.
* @param RequestCacheService $requestCacheService
*/
public function __construct(RequestCacheService $requestCacheService) {
$this->requestCacheService = $requestCacheService;
}
public static function getSubscribedEvents(): array {
return [
AfterEntityPersistedEvent::class => 'clearRequestCache',
AfterEntityUpdatedEvent::class => 'clearRequestCache',
AfterEntityDeletedEvent::class => 'clearRequestCache',
];
}
public function clearRequestCache($event = null) {
$this->requestCacheService->clearAll();
}
}