custom/plugins/ShopStudioPixelYourShop/src/Framework/Adapter/Cache/CacheInvalidationSubscriber.php line 47

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace ShopStudio\PixelYourShop\Framework\Adapter\Cache;
  3. use ShopStudio\PixelYourShop\Pixel\PixelDefinition;
  4. use Shopware\Core\Framework\Adapter\Cache\CacheInvalidator;
  5. use Shopware\Core\Framework\DataAbstractionLayer\Event\EntityWrittenContainerEvent;
  6. use Shopware\Core\System\SystemConfig\CachedSystemConfigLoader;
  7. use Shopware\Core\System\SystemConfig\SystemConfigService;
  8. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  9. /**
  10.  * @since 2.0.0
  11.  */
  12. class CacheInvalidationSubscriber implements EventSubscriberInterface
  13. {
  14.     /**
  15.      * @since 2.0.0
  16.      */
  17.     private CacheInvalidator $cacheInvalidator;
  18.     /**
  19.      * @since 2.0.0
  20.      */
  21.     public function __construct(CacheInvalidator $cacheInvalidator)
  22.     {
  23.         $this->cacheInvalidator $cacheInvalidator;
  24.     }
  25.     /**
  26.      * @since 2.0.0
  27.      */
  28.     public static function getSubscribedEvents(): array
  29.     {
  30.         return [
  31.             EntityWrittenContainerEvent::class => [
  32.                 ['invalidateConfigKeys'2000],
  33.             ],
  34.         ];
  35.     }
  36.     /**
  37.      * Delete any config to clear the pixel-related cache.
  38.      *
  39.      * @since 2.0.0
  40.      */
  41.     public function invalidateConfigKeys(EntityWrittenContainerEvent $event): void
  42.     {
  43.         $pixelWrittenEvent $event->getEventByEntityName(PixelDefinition::ENTITY_NAME);
  44.         if ($pixelWrittenEvent === null) {
  45.             return;
  46.         }
  47.         $this->cacheInvalidator->invalidate([
  48.             SystemConfigService::buildName('ShopStudioPixelYourShop.config.cookieConsentProvider'),
  49.             SystemConfigService::buildName('ShopStudioPixelYourShop.config.debugEnabled'),
  50.             CachedSystemConfigLoader::CACHE_TAG,
  51.         ]);
  52.     }
  53. }