Ejemplo n.º 1
0
 public function testSendPurgeRequestWithException()
 {
     $uris[] = UriFactory::factory('')->setHost('127.0.0.1')->setPort(8080)->setScheme('http');
     $this->cacheServer->expects($this->once())->method('getUris')->willReturn($uris);
     $this->socketAdapterMock->method('connect')->willThrowException(new \Zend\Http\Client\Adapter\Exception\RuntimeException());
     $this->loggerMock->expects($this->never())->method('execute');
     $this->loggerMock->expects($this->once())->method('critical');
     $this->assertFalse($this->model->sendPurgeRequest('tags'));
 }
 /**
  * If Varnish 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::VARNISH && $this->config->isEnabled()) {
         $object = $observer->getEvent()->getObject();
         if ($object instanceof \Magento\Framework\DataObject\IdentityInterface) {
             $tags = [];
             $pattern = "((^|,)%s(,|\$))";
             foreach ($object->getIdentities() as $tag) {
                 $tags[] = sprintf($pattern, preg_replace("~_\\d+\$~", '', $tag));
                 $tags[] = sprintf($pattern, $tag);
             }
             $this->purgeCache->sendPurgeRequest(implode('|', array_unique($tags)));
         }
     }
 }
 /**
  * Flush CloudFlare cache
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return void
  */
 public function execute(Observer $observer)
 {
     if ($this->config->isEnabled()) {
         $this->cacheTags->purgeCache();
     }
 }
 /**
  * Flash Varnish cache
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return void
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     if ($this->config->getType() == \Magento\PageCache\Model\Config::VARNISH && $this->config->isEnabled()) {
         $this->purgeCache->sendPurgeRequest('.*');
     }
 }