title: C# HttpWebRequest Cache
body: <p>In my app I build a GET request intended to return a response from cache whenever the contents are the same as on the server.</p>
  
  <pre><code>            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
              request.Method = "GET";                
              request.ReadWriteTimeout = 2000;
              request.KeepAlive = true;
              request.AutomaticDecompression = DecompressionMethods.GZip;
  
              request.CachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.Revalidate);
              request.Host = host;
              request.Referer = referer;
              request.UserAgent = ua;
  
              request.Accept = "text/javascript, text/html, application/xml, text/xml, */*";
              request.ContentType = "application/json; charset=UTF-8";
              request.Headers.Add("Accept-Ranges", "bytes");
              request.Headers.Add("Accept-Encoding", "gzip, deflate, sdch");
              request.Headers.Add("Accept-Language", "en-US,en;q=0.8,en-US;q=0.5,en;q=0.3");
  
              using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
              {
                  if (response.StatusCode == HttpStatusCode.OK)
                  {
                          using (var stream = new StreamReader(response.GetResponseStream()))
                          {
                              content = stream.ReadToEnd();
                          }
                  }
                  else content = string.Empty;
              }
  </code></pre>
  
  <p>However the <code>request.GetResponse().IsFromCache</code> always returns false even if the contents are the same (I still can successfully read it with <code>StreamReader</code>).
  When I do the same two requests in browser consecutively it successfully caches.
  I've tried all the possible Cache Policies. Can anyone explain what I'm doing wrong?</p>