Kevinrob\GuzzleCache\CacheMiddleware::addToCache PHP Method

addToCache() protected static method

protected static addToCache ( Kevinrob\GuzzleCache\Strategy\CacheStrategyInterface $cache, Psr\Http\Message\RequestInterface $request, Psr\Http\Message\ResponseInterface $response, boolean $update = false ) : Psr\Http\Message\ResponseInterface
$cache Kevinrob\GuzzleCache\Strategy\CacheStrategyInterface
$request Psr\Http\Message\RequestInterface
$response Psr\Http\Message\ResponseInterface
$update boolean cache
return Psr\Http\Message\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;
    }