OutputCache serving long-stale data
Asked Answered
W

1

11

I'm flumoxed... re this and this "meta" questions...

A very basic http request:

GET http://stackoverflow.com/feeds/tag?tagnames=c%23&sort=newest HTTP/1.1
Host: stackoverflow.com
Accept-Encoding: gzip,deflate

which hits a route decorated with:

[OutputCache(Duration = 300, VaryByParam = "tagnames;sort",
    VaryByContentEncoding = "gzip;deflate", VaryByCustom = "site")]

is repeatedly and incorrectly serving either a 304 (no change) if you include if-modified-since, or the old data for a 200, i.e.

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)

As you can see, it is serving this nearly half an hour past the 5 minute slot; it looks like the internals of OutputCache simply didn't notice the time ;p It will expire eventually (in fact, it has just done so - my Fri, 01 Jul 2011 09:56:20 GMT request finally got fresh data), but not anywhere like punctually.

UPDATE:

I believed 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 VaryByContentEncoding):

GET http://stackoverflow.com/feeds/tag?tagnames=c%23&sort=newest HTTP/1.1
Host: stackoverflow.com

gives:

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)

Once again, you'll notice it is being served after Expires.

So: what could be wrong here?

Additional; while we are using a custom option, our GetVaryByCustomString() correctly calls base.GetVaryByCustomString(ctx, custom) for options it doesn't recognise, as per MSDN (indeed this works fine for the second example above).

Woman answered 1/7, 2011 at 9:59 Comment(3)
Marc your custom output cache provider wouldn't happen to be open sourced somewhere would it?Induna
@runxc1 I'd have to check, but our default "go to" tool there is red is via booksleeve (both of which are open source) using some custom wrappers (that are not). However, it sounds wrong in my head to think redis here - I'll have to take a look at the code.Woman
Did you ever find the custom output cache provider? Just curious as it feels like the baked in ones are really lacking.Induna
C
10

Is there any chance you're using a custom output cache provider? Hypothetically, if there was a custom provider using say a sliding expiration instead of an absolute one, you'd see symptoms like this.

Calcine answered 1/7, 2011 at 11:12 Comment(5)
Yes; it turns out that we suckWoman
Jeff will fire you for failing to suck a little less today ;))Aschim
Ah well, at least we didn't mess up the time unit; that would be embarrassingWoman
Cache is overrated, your site should be fast enough not to need it.Scornik
@hofnarwillie oh I dunno, I think Stack Overflow is fairing pretty well still :) Also, he was joking - watch our Channel 9 spot from MIX 2011 to get the reference.Calcine

© 2022 - 2024 — McMap. All rights reserved.