/**
  * If Built-In caching is enabled it collects array of tags
  * of incoming object and asks to clean cache.
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return void
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     if ($this->_config->getType() == \Magento\PageCache\Model\Config::BUILT_IN && $this->_config->isEnabled()) {
         $object = $observer->getEvent()->getObject();
         if ($object instanceof \Magento\Framework\Object\IdentityInterface) {
             $tags = $object->getIdentities();
             foreach ($tags as $tag) {
                 $tags[] = preg_replace("~_\\d+\$~", '', $tag);
             }
             $this->_cache->clean(array_unique($tags));
         }
     }
 }
 public function testExecuteWithEmptyTags()
 {
     $this->_configMock->expects($this->any())->method('isEnabled')->will($this->returnValue(true));
     $observerObject = $this->getMock('Magento\\Framework\\Event\\Observer');
     $observedObject = $this->getMock('Magento\\Store\\Model\\Store', [], [], '', false);
     $tags = [];
     $eventMock = $this->getMock('Magento\\Framework\\Event', ['getObject'], [], '', false);
     $eventMock->expects($this->once())->method('getObject')->will($this->returnValue($observedObject));
     $observerObject->expects($this->once())->method('getEvent')->will($this->returnValue($eventMock));
     $this->_configMock->expects($this->once())->method('getType')->will($this->returnValue(\Magento\PageCache\Model\Config::BUILT_IN));
     $observedObject->expects($this->once())->method('getIdentities')->will($this->returnValue($tags));
     $this->_cacheMock->expects($this->never())->method('clean');
     $this->_model->execute($observerObject);
 }
 /**
  * Test case for cache invalidation
  *
  * @dataProvider flushCacheByTagsDataProvider
  * @param $cacheState
  */
 public function testExecute($cacheState)
 {
     $this->_configMock->expects($this->any())->method('isEnabled')->will($this->returnValue($cacheState));
     $observerObject = $this->getMock('Magento\\Framework\\Event\\Observer');
     $observedObject = $this->getMock('Magento\\Store\\Model\\Store', [], [], '', false);
     if ($cacheState) {
         $tags = ['cache_1', 'cache_group'];
         $expectedTags = ['cache_1', 'cache_group', 'cache'];
         $eventMock = $this->getMock('Magento\\Framework\\Event', ['getObject'], [], '', false);
         $eventMock->expects($this->once())->method('getObject')->will($this->returnValue($observedObject));
         $observerObject->expects($this->once())->method('getEvent')->will($this->returnValue($eventMock));
         $this->_configMock->expects($this->once())->method('getType')->will($this->returnValue(\Magento\PageCache\Model\Config::BUILT_IN));
         $observedObject->expects($this->once())->method('getIdentities')->will($this->returnValue($tags));
         $this->_cacheMock->expects($this->once())->method('clean')->with($this->equalTo($expectedTags));
     }
     $this->_model->execute($observerObject);
 }
 /**
  * {@inheritdoc}
  */
 public function clean($tags = array())
 {
     $pluginInfo = $this->pluginList->getNext($this->subjectType, 'clean');
     if (!$pluginInfo) {
         return parent::clean($tags);
     } else {
         return $this->___callPlugins('clean', func_get_args(), $pluginInfo);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function save($data, $identifier, $tags = array(), $lifeTime = null)
 {
     $pluginInfo = $this->pluginList->getNext($this->subjectType, 'save');
     if (!$pluginInfo) {
         return parent::save($data, $identifier, $tags, $lifeTime);
     } else {
         return $this->___callPlugins('save', func_get_args(), $pluginInfo);
     }
 }
Exemple #6
0
 /**
  * @dataProvider processNotSaveCacheProvider
  * @param string $cacheControlHeader
  * @param int $httpCode
  * @param bool $isGet
  * @param bool $overrideHeaders
  */
 public function testProcessNotSaveCache($cacheControlHeader, $httpCode, $isGet, $overrideHeaders)
 {
     $this->responseMock->expects($this->once())->method('getHeader')->with('Cache-Control')->will($this->returnValue(array('value' => $cacheControlHeader)));
     $this->responseMock->expects($this->any())->method('getHttpResponseCode')->will($this->returnValue($httpCode));
     $this->requestMock->expects($this->any())->method('isGet')->will($this->returnValue($isGet));
     if ($overrideHeaders) {
         $this->responseMock->expects($this->once())->method('setNoCacheHeaders');
     }
     $this->cacheMock->expects($this->never())->method('save');
     $this->kernel->process($this->responseMock);
 }
Exemple #7
0
 /**
  * Flash Built-In cache
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return void
  * 
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function flushAllCache(\Magento\Framework\Event\Observer $observer)
 {
     if ($this->_config->getType() == \Magento\PageCache\Model\Config::BUILT_IN) {
         $this->_cache->clean();
     }
 }
 /**
  * Flash Built-In cache
  *
  * @return void
  */
 public function execute()
 {
     if ($this->_config->getType() == \Magento\PageCache\Model\Config::BUILT_IN) {
         $this->_cache->clean();
     }
 }
 /**
  * Test case for flushing all the cache
  */
 public function testExecute()
 {
     $this->_configMock->expects($this->once())->method('getType')->will($this->returnValue(\Magento\PageCache\Model\Config::BUILT_IN));
     $this->_cacheMock->expects($this->once())->method('clean');
     $this->_model->execute();
 }