/** * Tries to obtain cached response. * * @param Request $request * * @return Response|null Will return cached content as response or null if there's nothing to return. * @throws SecurityViolationException Tried to obtain cache entry using unsafe path. Generally it should never occur * unless invalid Request is passed. */ public function retrieveCachedResponse(Request $request) { if ($this->isCacheable($request) !== true) { return null; } $cacheElement = $this->cacheManager->getElement($request->getPathInfo()); if ($cacheElement === null) { return null; } return CacheResponse::createFromElement($cacheElement, $this->addStatusHeader ? 'HIT,PHP' : null); }
/** * 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); } }
/** * Clears any caches necessary. * * @param string $cacheDir The cache directory - it's unused because SupercacheBundle uses different directory * outside standard caching directory. */ public function clear($cacheDir) { $this->manager->clear(); }
/** * Deletes cache entry recursively. * * @param $event */ public function deleteCache($event) { $this->cacheManager->clear(); }