/** * Creates new CacheResponse object from given CacheElement. * * @param CacheElement $element * @param null $status Value for X-Supercache header. By default null (no header will be added). * * @return static */ public static function createFromElement(CacheElement $element, $status = null) { $mime = self::getMimeByType($element->getType()); $headers = array('Content-Type' => $mime); if ($status !== null) { $headers['X-Supercache'] = $status; } return new static($element->getContent(), static::HTTP_OK, $headers); }
/** * Method is executed as one of the last one in the whole Pimcore. * Saves a full static page if request is eligible to cache. */ public function dispatchLoopShutdown() { $this->checkRequest($this->_request); $body = $this->getResponse()->getBody(); $type = $body[0] === '{' ? CacheElement::TYPE_JAVASCRIPT : CacheElement::TYPE_HTML; if ($this->isEnabled()) { $this->checkExcludedPatterns($this->_request->getRequestUri()); $this->checkCookies(); } if (!$this->ignored && $this->getResponse()->getHttpResponseCode() == 200) { $cacheManager = new CacheManager($this->finder); $cacheElement = new CacheElement($this->_request->getRequestUri(), $body, $type); $cacheElement->setRawPath($this->_request->getRequestUri()); $cacheManager->saveElement($cacheElement); } }
/** * Saves entry content. If entry exists it will be updated, otherwise created. * * @param CacheElement $element * * @return bool * @throws FilesystemException * @throws SecurityViolationException Specified cache path was found to be dangerous (eg. /../../sandbox) */ public function saveElement(CacheElement $element) { $path = $element->getPath() . '/index.' . $element->getType(); //Type contains extension return $this->finder->writeFile($path, $element->getContent()); }