From 2de1c8ddaa14bd59c19d84886608bb34bfbcba73 Mon Sep 17 00:00:00 2001 From: Simon Vieille Date: Sun, 4 Apr 2021 20:09:16 +0200 Subject: [PATCH] update cache management (cache:clear is not a solution) --- core/Cache/SymfonyCacheManager.php | 11 ++++++++++- .../EntityManagerEventSubscriber.php | 14 ++++++++------ core/EventSuscriber/Site/MenuEventSubscriber.php | 2 +- core/EventSuscriber/Site/SiteEventSubscriber.php | 7 ++----- 4 files changed, 21 insertions(+), 13 deletions(-) diff --git a/core/Cache/SymfonyCacheManager.php b/core/Cache/SymfonyCacheManager.php index da72bad..4fb7fe2 100644 --- a/core/Cache/SymfonyCacheManager.php +++ b/core/Cache/SymfonyCacheManager.php @@ -40,12 +40,21 @@ class SymfonyCacheManager { $application = new Application($this->kernel); $application->setAutoExit(false); + $output = new BufferedOutput(); $input = new ArrayInput([ 'command' => 'cache:clear', + '-e' => $this->kernel->getEnvironment(), + '--no-warmup' => null, + ]); + + $application->run($input, $output); + + $input = new ArrayInput([ + 'command' => 'cache:warmup', + '-e' => $this->kernel->getEnvironment(), ]); - $output = new BufferedOutput(); $application->run($input, $output); } } diff --git a/core/EventSuscriber/EntityManagerEventSubscriber.php b/core/EventSuscriber/EntityManagerEventSubscriber.php index 586fbf4..8d663dc 100644 --- a/core/EventSuscriber/EntityManagerEventSubscriber.php +++ b/core/EventSuscriber/EntityManagerEventSubscriber.php @@ -12,15 +12,17 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface; */ abstract class EntityManagerEventSubscriber implements EventSubscriberInterface { + static protected int $priority = 0; + public static function getSubscribedEvents() { return [ - EntityManagerEvent::CREATE_EVENT => 'onCreate', - EntityManagerEvent::UPDATE_EVENT => 'onUpdate', - EntityManagerEvent::DELETE_EVENT => 'onDelete', - EntityManagerEvent::PRE_CREATE_EVENT => 'onPreCreate', - EntityManagerEvent::PRE_UPDATE_EVENT => 'onPreUpdate', - EntityManagerEvent::PRE_DELETE_EVENT => 'onPreDelete', + EntityManagerEvent::CREATE_EVENT => ['onCreate', self::$priority], + EntityManagerEvent::UPDATE_EVENT => ['onUpdate', self::$priority], + EntityManagerEvent::DELETE_EVENT => ['onDelete', self::$priority], + EntityManagerEvent::PRE_CREATE_EVENT => ['onPreCreate', self::$priority], + EntityManagerEvent::PRE_UPDATE_EVENT => ['onPreUpdate', self::$priority], + EntityManagerEvent::PRE_DELETE_EVENT => ['onPreDelete', self::$priority], ]; } diff --git a/core/EventSuscriber/Site/MenuEventSubscriber.php b/core/EventSuscriber/Site/MenuEventSubscriber.php index 72335c3..56ab531 100644 --- a/core/EventSuscriber/Site/MenuEventSubscriber.php +++ b/core/EventSuscriber/Site/MenuEventSubscriber.php @@ -88,7 +88,7 @@ class MenuEventSubscriber extends EntityManagerEventSubscriber $this->nodeRepository->persistAsFirstChild($childNode, $rootNode); - $this->cacheManager->cleanAll(); + $this->cacheManager->cleanRouting(); } public function onUpdate(EntityManagerEvent $event) diff --git a/core/EventSuscriber/Site/SiteEventSubscriber.php b/core/EventSuscriber/Site/SiteEventSubscriber.php index 6c6a8c3..d46435c 100644 --- a/core/EventSuscriber/Site/SiteEventSubscriber.php +++ b/core/EventSuscriber/Site/SiteEventSubscriber.php @@ -21,6 +21,7 @@ class SiteEventSubscriber extends EntityManagerEventSubscriber { protected KernelInterface $kernel; protected SymfonyCacheManager $cacheManager; + static protected int $priority = -1; public function __construct(KernelInterface $kernel, SymfonyCacheManager $cacheManager) { @@ -39,11 +40,7 @@ class SiteEventSubscriber extends EntityManagerEventSubscriber return; } - if ($event->getEntity() instanceof Node) { - $this->cacheManager->cleanRouting(); - } else { - $this->cacheManager->cleanAll(); - } + $this->cacheManager->cleanRouting(); } public function onCreate(EntityManagerEvent $event)