/** * Saves content to cache. * * @param string $path HTTP path. * @param string $content Raw content to cache. * @param string $contentType Response Content-Type. It can be just plain MIME type or like "text/html; * charset=UTF-8" * * @return bool * @throws SecurityViolationException */ private function cachePush($path, $content, $contentType) { //Guess cache type from mime. Basic rules were defined by https://github.com/kiler129/SupercacheBundle/issues/2 if (strpos($contentType, '/javascript') !== false || strpos($contentType, '/json') !== false) { $type = CacheElement::TYPE_JAVASCRIPT; } elseif (strpos($contentType, 'text/') !== false) { $type = CacheElement::TYPE_HTML; } else { $type = CacheElement::TYPE_BINARY; } $element = new CacheElement($path, $content, $type); return $this->cacheManager->saveElement($element); }
/** * 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); } }