protected function handleCacheFromResponse(Response $response, $result)
    {
        // Handle caching if requested
        if ($cacheControl = $response->getHeader('Cache-Control')) {
            // Combine separate header rows
            $cacheControl = implode(', ', $cacheControl);

            if (strpos($cacheControl, 'no-store') === false
                && preg_match('/(?:max-age=)(\d+)/i', $cacheControl, $matches)
            ) {
                $duration = (int) $matches[1];

                $cacheKey = $this->getCacheKey();
                $this->setToCache($cacheKey, $result, $duration);
            }
        }
    }