Headers expire when testing in Chrome

The heading "Expires" is very confusing here! Sometimes it works as expected - and sometimes not.

I use the following code to set expiration headers. Note that this is done with ASP.NET in a custom MVC attribute - it doesn't really matter here, but explains where it comes from 'filterContext'.

HttpCachePolicyBase cache = filterContext.HttpContext.Response.Cache;
TimeSpan cacheDuration = TimeSpan.FromSeconds(Duration);

// my own custom header so we know what time it was
filterContext.HttpContext.Response.AddHeader("CurrentTime", DateTime.Now.ToString());

cache.SetCacheability(HttpCacheability.Public);
cache.SetExpires(DateTime.Now.Add(cacheDuration));
cache.SetMaxAge(cacheDuration);
cache.AppendCacheExtension("must-revalidate, proxy-revalidate");

This sometimes gives me the following headers:

Cache-Control: public, must-revalidate, proxy-revalidate, max-age=413
Date: Wed, 18 Feb 2009 05:24:19 GMT
Expires: Wed, 18 Feb 2009 05:21:12 GMT
CurrentTime: 2/17/2009 9:21:12 PM

Sometimes it looks like this:

Cache-Control: public, must-revalidate, proxy-revalidate, max-age=600
Date: Wed, 18 Feb 2009 05:27:55 GMT
Expires: Wed, 18 Feb 2009 05:27:55 GMT
CurrentTime: 2/17/2009 9:27:55 PM

I run everything through Fiddler and look to see when everything is requested and when they come from the browser cache.

Now it’s strange that caching always works as expected. The link to my ASP.NET MVC action method appears in Fiddler, and then when I click the same link again, it comes from the cache.

Chrome ! , HTTP-.

, :

 http://ipv4.fiddler:62669/gallery/mainimage/2

IE, 200 . Chrome . - .

Chrome - "" - ?

, - , Expires . google jQuery , ( Expires 2010 - ).

Cache-Control: public, max-age=31536000
Date: Wed, 18 Feb 2009 05:44:53 GMT
Expires: Thu, 18 Feb 2010 05:44:53 GMT

?

HTTP:

Expires , max-age , . , HTTP/1.1 ( ), HTTP/1.0 . , HTTP/1.0 , , - .

, Chrome max-age, "Expires" , , , .

+5
2

ASP.NET MVC:

 public virtual void RenderView(ViewContext viewContext) {
        // TODO: Remove this hack. Without it, the browser appears to always load cached output
        viewContext.HttpContext.Response.Cache.SetExpires(DateTime.Now);
        ViewUserControlContainerPage containerPage = new ViewUserControlContainerPage(this);
        // Tracing requires Page IDs to be unique.
        ID = Guid.NewGuid().ToString();

        RenderViewAndRestoreContentType(containerPage, viewContext);
    }

, , Expires . , , Chrome, , Chrome 200

public partial class test : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        TimeSpan cacheDuration = TimeSpan.FromSeconds(33);
       var cache = Response.Cache;

        cache.SetCacheability(HttpCacheability.Public);
        cache.SetExpires(DateTime.Now.Add(cacheDuration));
        cache.SetMaxAge(cacheDuration);
        cache.AppendCacheExtension("must-revalidate, proxy-revalidate");
    }
}
+3

, Chrome - .

- jQuery Google.

:

http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js 

Chrome, Fiddler 200 :

Requests started at:    22:58:00:7756
Responses completed at: 22:58:03:5020
Total Sequence time:    00:00:02.7263880
DNS Lookup time:    531ms
TCP/IP Connect time:    63ms

RESPONSE CODES
--------------
HTTP/200:   1

( 1 ):

Cache-Control: public, max-age=31536000
Date: Wed, 18 Feb 2009 06:58:01 GMT
Expires: Thu, 18 Feb 2010 06:58:01 GMT
Vary: Accept-Encoding

enter - . Fiddler ** 200 * :

Requests started at:    22:58:09:2516
Responses completed at: 22:58:12:3999
Total Sequence time:    00:00:03.1482360

RESPONSE CODES
--------------
HTTP/200:   1

:

Cache-Control: public, max-age=31536000
Date: Wed, 18 Feb 2009 06:58:09 GMT
Expires: Thu, 18 Feb 2010 06:58:09 GMT
Vary: Accept-Encoding

, , .

. - .

. 304

Chrome, , Fiddler .

, - . - , . , ASP.NET MVC, -, Expires . , , Google.

, Chrome , - 1.0.154.48.

+1

All Articles