/**
* @param CacheStrategyInterface $cache
* @param RequestInterface $request
* @param ResponseInterface $response
* @param bool $update cache
* @return ResponseInterface
*/
protected static function addToCache(CacheStrategyInterface $cache, RequestInterface $request, ResponseInterface $response, $update = false)
{
// If the body is not seekable, we have to replace it by a seekable one
if (!$response->getBody()->isSeekable()) {
$response = $response->withBody(\GuzzleHttp\Psr7\stream_for($response->getBody()->getContents()));
}
if ($update) {
$cache->update($request, $response);
} else {
$cache->cache($request, $response);
}
return $response;
}