/** * Returns the cached value for the given request or NULL if it is not * defined * * @param \Cundd\Rest\Request $request * @return \Bullet\Response */ public function getCachedValueForRequest(\Cundd\Rest\Request $request) { $this->currentRequest = $request; /** @var \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend $cacheInstance */ $cacheInstance = NULL; $cacheLifeTime = $this->getCacheLifeTime(); /* * Use caching if the cache life time configuration is not -1, an API * path is given and the request is a read request */ $useCaching = $cacheLifeTime !== -1 && $request->path(); if (!$useCaching) { return NULL; } $cacheInstance = $this->_getCacheInstance(); $responseArray = $cacheInstance->get($this->_getCacheKey()); if (!$responseArray) { return NULL; } if (!$request->isRead()) { $this->_clearCache(); return NULL; } /** TODO: Send 304 status if appropriate */ $response = new Response($responseArray['content'], $responseArray['status']); $response->contentType($responseArray['content-type']); $response->encoding($responseArray['encoding']); $response->header('Last-Modified', $responseArray['last-modified']); $response->header('Expires', $this->getHttpDate(time() + $this->getExpiresHeaderLifeTime())); $response->header('cundd-rest-cached', 'true'); return $response; }