Example #1
0
 /**
  * Sets the cache value for the given request
  *
  * @param \Cundd\Rest\Request $request
  * @param \Bullet\Response $response
  */
 public function setCachedValueForRequest(\Cundd\Rest\Request $request, Response $response)
 {
     $this->currentRequest = $request;
     /** @var \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend $cacheInstance */
     $cacheInstance = NULL;
     // Don't cache exceptions
     if ($response->content() instanceof \Exception) {
         return;
     }
     // Don't cache write requests
     if ($request->isWrite()) {
         return;
     }
     $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;
     }
     $cacheInstance = $this->_getCacheInstance();
     $cacheInstance->set($this->_getCacheKey(), array('content' => (string) $response, 'status' => $response->status(), 'encoding' => $response->encoding(), 'content-type' => $response->contentType(), 'last-modified' => $this->getHttpDate(time())), $this->_getTags(), $cacheLifeTime);
 }