Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CleanCache.php
Go to the documentation of this file.
1 <?php
7 
8 use \Magento\Framework\App\CacheInterface;
9 
11 {
15  protected $context;
16 
20  protected $eventManager;
21 
25  private $cache;
26 
31  public function __construct(
32  \Magento\Framework\Indexer\CacheContext $context,
33  \Magento\Framework\Event\Manager $eventManager
34  ) {
35  $this->context = $context;
36  $this->eventManager = $eventManager;
37  }
38 
46  public function afterUpdateMview(\Magento\Indexer\Model\Processor $subject)
47  {
48  $this->eventManager->dispatch('clean_cache_after_reindex', ['object' => $this->context]);
49  if (!empty($this->context->getIdentities())) {
50  $this->getCache()->clean($this->context->getIdentities());
51  }
52  }
53 
61  public function afterReindexAllInvalid(\Magento\Indexer\Model\Processor $subject)
62  {
63  $this->eventManager->dispatch('clean_cache_by_tags', ['object' => $this->context]);
64  if (!empty($this->context->getIdentities())) {
65  $this->getCache()->clean($this->context->getIdentities());
66  }
67  }
68 
75  private function getCache()
76  {
77  if ($this->cache === null) {
78  $this->cache = \Magento\Framework\App\ObjectManager::getInstance()->get(CacheInterface::class);
79  }
80  return $this->cache;
81  }
82 }
__construct(\Magento\Framework\Indexer\CacheContext $context, \Magento\Framework\Event\Manager $eventManager)
Definition: CleanCache.php:31
afterUpdateMview(\Magento\Indexer\Model\Processor $subject)
Definition: CleanCache.php:46
afterReindexAllInvalid(\Magento\Indexer\Model\Processor $subject)
Definition: CleanCache.php:61