Check if the response can be cached
bool Returns TRUE if the response can be cached or false if not
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();
}