private function handle200Response(RequestInterface $request, ResponseInterface $validateResponse, CompleteEvent $event) { // Store the 200 response in the cache if possible if (Utils::canCacheResponse($validateResponse)) { $this->storage->cache($request, $validateResponse); } $event->intercept($validateResponse); }
/** * Checks if the request and response can be cached, and if so, store it */ public function onComplete(CompleteEvent $event) { $request = $event->getRequest(); $response = $event->getResponse(); // Cache the response if it can be cached and isn't already if ($request->getConfig()->get('cache_lookup') === 'MISS' && call_user_func($this->canCache, $request) && Utils::canCacheResponse($response)) { $this->storage->cache($request, $response); } $this->addResponseHeaders($request, $response); }
/** * Checks if the request and response can be cached, and if so, store it. * * @param CompleteEvent $event */ public function onComplete(CompleteEvent $event) { $request = $event->getRequest(); $response = $event->getResponse(); // Cache the response if it can be cached and isn't already if ($request->getConfig()->get('cache_lookup') === 'MISS' && call_user_func($this->canCache, $request) && Utils::canCacheResponse($response)) { // Store the date when the response was cached $response->setHeader('X-Guzzle-Cache-Date', gmdate('D, d M Y H:i:s T', time())); $this->storage->cache($request, $response); } $this->addResponseHeaders($request, $response); }
/** * When the request is completed, it's cached. * * @param CompleteEvent $event Guzzle 4/5 event. * * @return void */ public function onComplete(CompleteEvent $event) { $response = $event->getResponse(); if (!Utils::canCacheResponse($response)) { return; } $request = $this->request; $keys = [$request->getMethod() . ' ' . $request->getUrl(), $request->getMethod() . ' ' . $response->getEffectiveUrl()]; $ttl = $this->getTtl($response); foreach ($keys as $key) { $this->cache->save($key, $response, $ttl); } }