views:

346

answers:

2

In my latest project which is in RC1 I have noticed that I have this browser caching issue that I just can't shake. This is what my header looks like

HTTP/1.1 200 OK
Date: Tue, 03 Mar 2009 15:11:34 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
X-AspNet-Version: 2.0.50727
X-AspNetMvc-Version: 1.0
Cache-Control: private
Expires: Tue, 03 Mar 2009 15:11:34 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 4614

Now technically if this is private it shouldn't have an expiration date on the content right? I've tried no-cache as well with the same results. Anybody have any experience with this particular issue?

+3  A: 

Cache-Control: private only specifies that the response is only intended for a single user and should not be stored in a shared cache (say, in a proxy) and used to serve requests for other users. I don't see anything in the protocol documentation that would preclude the use of an Expires header with a value. In fact, it seems a perfectly reasonable thing to say "use this for subsequent requests for this user only, but not after this time." There are other values for Cache-Control where Expires may not make sense, but I believe that the protocol has a means for disambiguating between conflicting headers (See section 4 of the protocol docs).

Quoting from Section 16.2 of the HTTP 1.1 protocol docs:

private

  Indicates that all or part of the response message is intended for
  a single user and MUST NOT be cached by a shared cache.  This
  allows an origin server to state that the specified parts of the
  response are intended for only one user and are not a valid
  response for requests by other users.  A private (non-shared)
  cache MAY cache the response.

  Note: This usage of the word private only controls where the
  response may be cached, and cannot ensure the privacy of the
  message content.
tvanfosson
why does no-cache not work then?
Al Katawazi
Can you define "not work" -- according to the protocol the presence of the Expires header is immaterial if Cache-Control is set to no-cache, but that doesn't mean that the header is forbidden. If the request is cached regardless of the no-cache setting, that's a problem with the cache itself.
tvanfosson
Reading through the protocol docs, it appears that many Http 1.0 caches ignore no-cache and treat an Expires equal to the date on the request as equivalent. This would imply that if you are worried about interoperability you would set both on your response.
tvanfosson
+1  A: 

There's no reason why private content can't be cached, its just that it should only be cached by the browser in the current users context, it should not be cached server side or by other caches such as a proxy server.

AnthonyWJones