public function Response::canCache

Check if the response can be cached

Return value

bool Returns TRUE if the response can be cached or false if not

File

drupal/core/vendor/guzzle/http/Guzzle/Http/Message/Response.php, line 800

Class

Response
Guzzle HTTP response object

Namespace

Guzzle\Http\Message

Code

public function canCache() {

  // Check if the response is cacheable based on the code
  if (!in_array((int) $this
    ->getStatusCode(), $this->cacheResponseCodes)) {
    return false;
  }

  // Make sure a valid body was returned and can be cached
  if ((!$this
    ->getBody()
    ->isReadable() || !$this
    ->getBody()
    ->isSeekable()) && ($this
    ->getContentLength() > 0 || $this
    ->getTransferEncoding() == 'chunked')) {
    return false;
  }

  // Never cache no-store resources (this is a private cache, so private
  // can be cached)
  if ($this
    ->hasCacheControlDirective('no-store')) {
    return false;
  }
  return $this
    ->isFresh() || $this
    ->getFreshness() === null || $this
    ->canValidate();
}