title: Caching Serialized HttpResponseMessage to Redis. Error on read. "InvalidOperationException: The stream was already consumed. It cannot be read again."
body: <p>I have a function that takes an API request, checks if the result exists in a Redis cache, if it does it returns the cached value, if not it sends the API request and then caches the value.</p>
  
  <pre><code>private async Task&lt;HttpResponseMessage&gt; RestGetCachedAsync(string query, ILogger logger = null)
      {
          string key = $"GET:{query}";
          HttpResponseMessage response;
  
          var cacheResponse = await _cacheService.GetStringValue(key);
  
          if (cacheResponse != null)
          {
              response = JsonConvert.DeserializeObject&lt;HttpResponseMessage&gt;(cacheResponse, new JsonSerializerSettings
              {
                  TypeNameHandling = TypeNameHandling.Auto,
                  NullValueHandling = NullValueHandling.Ignore,
              });
  
              if(response.IsSuccessStatusCode) return response;
          }
  
          response = await RestGetAsync(query, logger);
  
          if (response.IsSuccessStatusCode)
          {
              await _cacheService.SetStringValue(key, JsonConvert.SerializeObject(response, new JsonSerializerSettings
              {
                  TypeNameHandling = TypeNameHandling.Auto,
                  NullValueHandling = NullValueHandling.Ignore,
              }));
          }            
  
          return response;
      }
  </code></pre>
  
  <p>When reading a previously queried API </p>
  
  <pre><code>public async Task&lt;string&gt; DeserializeHttpResponse(HttpResponseMessage response)
      {
          return await response.Content.ReadAsStringAsync();
      }
  </code></pre>
  
  <p>I get the following error.</p>
  
  <pre><code>InvalidOperationException: The stream was already consumed. It cannot be read again.
  </code></pre>