26 $this->storage = $cache;
34 $validateResponse = $revalidate->send();
35 if ($validateResponse->getStatusCode() == 200) {
37 } elseif ($validateResponse->getStatusCode() == 304) {
40 }
catch (BadResponseException $e) {
49 public function shouldRevalidate(RequestInterface $request, Response $response)
55 $reqCache = $request->getHeader(
'Cache-Control');
56 $resCache = $response->getHeader(
'Cache-Control');
58 $revalidate = $request->getHeader(
'Pragma') ==
'no-cache' ||
59 ($reqCache && ($reqCache->hasDirective(
'no-cache') || $reqCache->hasDirective(
'must-revalidate'))) ||
60 ($resCache && ($resCache->hasDirective(
'no-cache') || $resCache->hasDirective(
'must-revalidate')));
63 if (!$revalidate && !$resCache && $response->hasHeader(
'ETag')) {
81 if ($e->getResponse()->getStatusCode() == 404) {
82 $this->storage->delete($e->getRequest());
97 $revalidate = clone $request;
98 $revalidate->removeHeader(
'Pragma')->removeHeader(
'Cache-Control');
100 if ($response->getLastModified()) {
101 $revalidate->setHeader(
'If-Modified-Since', $response->getLastModified());
104 if ($response->getEtag()) {
105 $revalidate->setHeader(
'If-None-Match', $response->getEtag());
109 $dispatcher = $revalidate->getEventDispatcher();
110 foreach ($dispatcher->getListeners() as $eventName => $listeners) {
111 foreach ($listeners as $listener) {
112 if (is_array($listener) && $listener[0] instanceof CachePlugin) {
113 $dispatcher->removeListener($eventName, $listener);
129 protected function handle200Response(RequestInterface $request, Response $validateResponse)
131 $request->setResponse($validateResponse);
132 if ($this->canCache->canCacheResponse($validateResponse)) {
133 $this->storage->cache($request, $validateResponse);
150 static $replaceHeaders = array(
'Date',
'Expires',
'Cache-Control',
'ETag',
'Last-Modified');
153 if ($validateResponse->
getEtag() != $response->getEtag()) {
160 foreach ($replaceHeaders as $name) {
161 if ($validateResponse->
hasHeader($name)) {
163 $response->setHeader($name, $validateResponse->
getHeader($name));
168 if ($modified && $this->canCache->canCacheResponse($response)) {
169 $this->storage->cache($request, $response);