src/EventSubscriber/AdminCacheSubscriber.php line 34

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber;
  3. use App\Services\RequestCacheService;
  4. use EasyCorp\Bundle\EasyAdminBundle\Event\AfterEntityDeletedEvent;
  5. use EasyCorp\Bundle\EasyAdminBundle\Event\AfterEntityPersistedEvent;
  6. use EasyCorp\Bundle\EasyAdminBundle\Event\AfterEntityUpdatedEvent;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. class AdminCacheSubscriber implements EventSubscriberInterface {
  9.     /**
  10.      * @var RequestCacheService
  11.      */
  12.     protected $requestCacheService;
  13.     /**
  14.      * AdminCacheSubscriber constructor.
  15.      * @param RequestCacheService $requestCacheService
  16.      */
  17.     public function __construct(RequestCacheService $requestCacheService) {
  18.         $this->requestCacheService $requestCacheService;
  19.     }
  20.     public static function getSubscribedEvents(): array {
  21.         return [
  22.             AfterEntityPersistedEvent::class => 'clearRequestCache',
  23.             AfterEntityUpdatedEvent::class => 'clearRequestCache',
  24.             AfterEntityDeletedEvent::class => 'clearRequestCache',
  25.         ];
  26.     }
  27.     public function clearRequestCache($event null) {
  28.         $this->requestCacheService->clearAll();
  29.     }
  30. }