Skip to content
This repository has been archived by the owner on Oct 18, 2023. It is now read-only.

Commit

Permalink
Inject cache_tags.invalidator service as dependency injection to invl…
Browse files Browse the repository at this point in the history
…idate tags.
  • Loading branch information
miteshmap committed Jan 31, 2019
1 parent efed3d3 commit 080798c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
17 changes: 15 additions & 2 deletions modules/acm_promotion/src/AcmPromotionQueueBase.php
Expand Up @@ -7,6 +7,7 @@
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Queue\QueueWorkerBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Cache\CacheTagsInvalidatorInterface;

/**
* Class AcmPromotionQueueBase.
Expand All @@ -29,6 +30,13 @@ abstract class AcmPromotionQueueBase extends QueueWorkerBase implements Containe
*/
protected $logger;

/**
* The cache tags invalidator.
*
* @var \Drupal\Core\Cache\CacheTagsInvalidatorInterface
*/
protected $tagInvalidate;

/**
* AcmPromotionAttachQueue constructor.
*
Expand All @@ -42,15 +50,19 @@ abstract class AcmPromotionQueueBase extends QueueWorkerBase implements Containe
* IngestAPIWrapper Service object.
* @param \Drupal\Core\Logger\LoggerChannelFactory $loggerFactory
* Logger service.
* @param \Drupal\Core\Cache\CacheTagsInvalidatorInterface $tag_invalidate
* The cache tags invalidator.
*/
public function __construct(array $configuration,
$plugin_id,
$plugin_definition,
IngestAPIWrapper $ingestApiWrapper,
LoggerChannelFactory $loggerFactory) {
LoggerChannelFactory $loggerFactory,
CacheTagsInvalidatorInterface $tag_invalidate) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->ingestApiWrapper = $ingestApiWrapper;
$this->logger = $loggerFactory->get('acm_sku');
$this->tagInvalidate = $tag_invalidate;
}

/**
Expand All @@ -74,7 +86,8 @@ public static function create(ContainerInterface $container, array $configuratio
$plugin_id,
$plugin_definition,
$container->get('acm.ingest_api'),
$container->get('logger.factory')
$container->get('logger.factory'),
$container->get('cache_tags.invalidator')
);
}

Expand Down
Expand Up @@ -114,7 +114,7 @@ public function processItem($data) {
}

// Invalidate sku cache tags & related promotion nid.
Cache::invalidateTags($invalidate_tags);
$this->tagInvalidate->invalidateTags($invalidate_tags);

if (!empty($skus_not_found)) {
$this->logger->warning('Skus @skus not found in Drupal.',
Expand Down
Expand Up @@ -81,7 +81,7 @@ public function processItem($data) {
$sku_texts = implode(',', $skus);

// Invalidate cache tags for updated skus & promotions.
Cache::invalidateTags($invalidate_tags);
$this->tagInvalidate->invalidateTags($invalidate_tags);

$this->logger->info('Detached Promotion:@promo from SKUs: @skus',
['@promo' => $promotion_nid, '@skus' => $sku_texts]);
Expand Down

0 comments on commit 080798c

Please sign in to comment.