title: OutputCache serving long-stale data
body: <p>I'm flumoxed... re <a href="https://meta.stackexchange.com/questions/87062/whats-wrong-with-rss-feed">this</a> and <a href="https://meta.stackexchange.com/questions/86991/feeds-dont-expire">this</a> "meta" questions...</p>
  
  <p>A very basic http request:</p>
  
  <pre><code>GET http://stackoverflow.com/feeds/tag?tagnames=c%23&amp;sort=newest HTTP/1.1
  Host: stackoverflow.com
  Accept-Encoding: gzip,deflate
  </code></pre>
  
  <p>which hits a route decorated with:</p>
  
  <pre><code>[OutputCache(Duration = 300, VaryByParam = "tagnames;sort",
      VaryByContentEncoding = "gzip;deflate", VaryByCustom = "site")]
  </code></pre>
  
  <p>is repeatedly <strong><em>and incorrectly</em></strong> serving either a 304 (no change) if you include if-modified-since, or <em>the old data</em> for a 200, i.e.</p>
  
  <pre><code>HTTP/1.1 200 OK
  Cache-Control: public, max-age=0
  Content-Type: application/atom+xml; charset=utf-8
  Content-Encoding: gzip
  Expires: Fri, 01 Jul 2011 09:17:08 GMT
  Last-Modified: Fri, 01 Jul 2011 09:12:08 GMT
  Vary: *
  Date: Fri, 01 Jul 2011 09:42:46 GMT
  Content-Length: 14714
  (payload, when decoded = some long-stale data)
  </code></pre>
  
  <p>As you can see, it is serving this nearly half an hour <em>past</em> the 5 minute slot; it looks like the internals of OutputCache simply didn't notice the time ;p It will expire <em>eventually</em> (in fact, it has just done so - my <code>Fri, 01 Jul 2011 09:56:20 GMT</code> request finally got fresh data), but not anywhere like punctually.</p>
  
  <p>UPDATE:</p>
  
  <p>I <em>believed</em> that it was working if we took away the accept-encoding header, but no; this fails too - it just fails on a different cycle (which is what we should expect since the keys are different, courtesy of <code>VaryByContentEncoding</code>):</p>
  
  <pre><code>GET http://stackoverflow.com/feeds/tag?tagnames=c%23&amp;sort=newest HTTP/1.1
  Host: stackoverflow.com
  </code></pre>
  
  <p>gives:</p>
  
  <pre><code>HTTP/1.1 200 OK
  Cache-Control: public, max-age=0
  Content-Type: application/atom+xml; charset=utf-8
  Expires: Fri, 01 Jul 2011 10:09:58 GMT
  Last-Modified: Fri, 01 Jul 2011 10:04:58 GMT
  Vary: *
  Date: Fri, 01 Jul 2011 10:17:20 GMT
  Content-Length: 66815
  (payload = some stale data)
  </code></pre>
  
  <p>Once again, you'll notice it is being served <em>after</em> <code>Expires</code>.</p>
  
  <p>So: what could be wrong here?</p>
  
  <p>Additional; while we are using a custom option, our <code>GetVaryByCustomString()</code> correctly calls <code>base.GetVaryByCustomString(ctx, custom)</code> for options it doesn't recognise, as per <a href="http://msdn.microsoft.com/en-us/library/5ecf4420.aspx" rel="nofollow noreferrer">MSDN</a> (indeed this works fine for the second example above).</p>