0
votes

I have an slightly one-off scenario for a site I'm working on.

I am routing certain request paths to a custom HTTP module that dynamically outputs "static" content. By that, I mean javascript and css content. However, that content is generated dynamically by the module, but once generated, does not change very often.

So, I would like to cache the output of my custom module, but for some reason, neither cached content, nor 304's are being returned to the client like I would expect.

If I browse to a URL using Firefox, the local browser caching seems to work. The browser uses what it has cached locally and doesn't make a request to the server.

However, if I press F5 on a page, the browser attempts to re-fetch the file from the server, and the server subsequently redirects to the module, regenerates the content, and essentially serves it fresh. I would expect IIS to instead return 304 to the client, or serve the content from the cache and avoid calling the module entirely.

The module seems to be returning correct cache headers:

http://www.mydomain.com/SpecialPath/File_17aa85bf3bf430066a0524787be6af7b9363c8ae.js

Cache-Control public, max-age=1800

Content-Encoding gzip

Content-Length 60568

Content-Type application/x-javascript; charset=utf-8

Date Tue, 27 Mar 2012 20:25:42 GMT

Etag 17aa85bf3bf430066a0524787be6af7b9363c8ae

Last-Modified Tue, 27 Mar 2012 20:25:43 GMT

Server Microsoft-IIS/7.5

Vary Accept-Encoding

X-AspNet-Version 4.0.30319

When I use F5 the browser request headers also seem to be OK:

Cache-Control max-age=0

If-Modified-Since Tue, 27 Mar 2012 20:25:21 GMT

If-None-Match 17aa85bf3bf430066a0524787be6af7b9363c8ae

However, if I set a break point, I see the request being passed through to the module.

304 is never returned, and neither is the content ever served from the output cache.

Do I need to do anything extra or special to get output caching to cache content returned from a custom module?

Is there something possibly wrong with my headers?

1

1 Answers

2
votes

Last-Modified Tue, 27 Mar 2012 20:25:43 GMT If-Modified-Since Tue, 27 Mar 2012 20:25:21 GMT

The resource is modified 22 seconds after the I-M-S value, so 304 is not returned