// RFC2616: A response received with a status code of 200, 203, 300, 301 or 410
// MAY be stored by a cache […] unless a cache-control directive prohibits caching.
if ($response->headers->
hasCacheControlDirective('no-cache'
) ||
$response->headers->
hasCacheControlDirective('no-store'
) ) { return true;
} // Etag headers cannot be merged, they render the response uncacheable
// by default (except if the response also has max-age etc.).
if (null ===
$response->
getEtag() && \
in_array($response->
getStatusCode(),
[200, 203, 300, 301, 410
])) { return false;
} // RFC2616: A response received with any other status code (e.g. status codes 302 and 307)
// MUST NOT be returned in a reply to a subsequent request unless there are
// cache-control directives or another header(s) that explicitly allow it.
$cacheControl =
['max-age', 's-maxage', 'must-revalidate', 'proxy-revalidate', 'public', 'private'
];
foreach ($cacheControl as $key) { if ($response->headers->
hasCacheControlDirective($key)) { return false;
} }