/** * @param \Magento\Framework\Controller\ResultInterface $subject * @param callable $proceed * @param ResponseHttp $response * @return \Magento\Framework\Controller\ResultInterface * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function aroundRenderResult(\Magento\Framework\Controller\ResultInterface $subject, \Closure $proceed, ResponseHttp $response) { $result = $proceed($response); $usePlugin = $this->registry->registry('use_page_cache_plugin'); if (!$usePlugin || !$this->config->isEnabled() || $this->config->getType() != \Magento\PageCache\Model\Config::BUILT_IN) { return $result; } if ($this->state->getMode() == \Magento\Framework\App\State::MODE_DEVELOPER) { $cacheControlHeader = $response->getHeader('Cache-Control'); if ($cacheControlHeader instanceof \Zend\Http\Header\HeaderInterface) { $response->setHeader('X-Magento-Cache-Control', $cacheControlHeader->getFieldValue()); } $response->setHeader('X-Magento-Cache-Debug', 'MISS', true); } $tagsHeader = $response->getHeader('X-Magento-Tags'); $tags = []; if ($tagsHeader) { $tags = explode(',', $tagsHeader->getFieldValue()); $response->clearHeader('X-Magento-Tags'); } $tags = array_unique(array_merge($tags, [\Magento\PageCache\Model\Cache\Type::CACHE_TAG])); $response->setHeader('X-Magento-Tags', implode(',', $tags)); $this->kernel->process($response); return $result; }
/** * @param \Magento\Framework\App\FrontControllerInterface $subject * @param callable $proceed * @param \Magento\Framework\App\RequestInterface $request * @return \Magento\Framework\Controller\ResultInterface|\Magento\Framework\App\Response\Http * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function aroundDispatch(\Magento\Framework\App\FrontControllerInterface $subject, \Closure $proceed, \Magento\Framework\App\RequestInterface $request) { if (!$this->config->isEnabled() || $this->config->getType() != \Magento\PageCache\Model\Config::BUILT_IN) { return $proceed($request); } $this->version->process(); $result = $this->kernel->load(); if ($result === false) { $result = $proceed($request); if ($result instanceof ResponseHttp) { $this->addDebugHeaders($result); $this->kernel->process($result); } } else { $this->addDebugHeader($result, 'X-Magento-Cache-Debug', 'HIT', true); } return $result; }
/** * @param \Magento\Framework\App\FrontControllerInterface $subject * @param callable $proceed * @param \Magento\Framework\App\RequestInterface $request * @return false|\Magento\Framework\App\Response\Http */ public function aroundDispatch(\Magento\Framework\App\FrontControllerInterface $subject, \Closure $proceed, \Magento\Framework\App\RequestInterface $request) { if ($this->config->getType() == \Magento\PageCache\Model\Config::BUILT_IN && $this->config->isEnabled()) { $this->version->process(); $response = $this->kernel->load(); if ($response === false) { $response = $proceed($request); $cacheControl = $response->getHeader('Cache-Control')['value']; $this->addDebugHeader($response, 'X-Magento-Cache-Control', $cacheControl); $this->kernel->process($response); $this->addDebugHeader($response, 'X-Magento-Cache-Debug', 'MISS'); } else { $this->addDebugHeader($response, 'X-Magento-Cache-Debug', 'HIT'); } } else { return $response = $proceed($request); } return $response; }
/** * @dataProvider processNotSaveCacheProvider * @param string $cacheControlHeader * @param int $httpCode * @param bool $isGet * @param bool $overrideHeaders */ public function testProcessNotSaveCache($cacheControlHeader, $httpCode, $isGet, $overrideHeaders) { $header = \Zend\Http\Header\CacheControl::fromString("Cache-Control: {$cacheControlHeader}"); $this->responseMock->expects($this->once())->method('getHeader')->with('Cache-Control')->will($this->returnValue($header)); $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->fullPageCacheMock->expects($this->never())->method('save'); $this->kernel->process($this->responseMock); }