HighTechTalks DotNet Forums  

HttpCachePolicy in an IHttpModule

ASP.net Caching microsoft.public.dotnet.framework.aspnet.caching


Discuss HttpCachePolicy in an IHttpModule in the ASP.net Caching forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Owen Blacker
 
Posts: n/a

Default HttpCachePolicy in an IHttpModule - 01-30-2006 , 11:31 AM






I'm having some trouble sorting out image caching for JPEGs that are
served through an IHttpModule.

A quirk of the site I'm working on at the moment is that product images
are served via a third-party image hosting provider (Scene7, who have
been very helpful and so deserve a credit). In order to save having to
reference the URI stem all over our code, I wrote an IHttpModule that
parses all requests on the basis of:

HttpContext context = ((HttpApplication) sender).Context;
HttpRequest request = context.Request;

Regex r = new Regex(
@"/images/products/(?<sku>[A-Z0-9-]+)_(?<size>\d)\.jpg",
RegexOptions.Compiled | RegexOptions.IgnoreCase);
Match m = r.Match(request.RawUrl);

if (m.Success && request.HttpMethod == "GET")
{
// Handle the Scene7-specific stuff
}
else
{
// Set cacheability
}

Before I was doing anything in this else clause, Fiddler
(www.fiddlertool.com) was showing me that the following headers were
being sent with all non-Scene7 JPEGs:

Pragma: no-cache
Cache-Control: no-cache
Pragma: no-cache
Expires: -1

Now, if I add the following two lines to my else clause:

HttpCachePolicy cache = context.Response.Cache;
cache.SetAllowResponseInBrowserHistory(true);

it gets rid of the "Expires: -1" header. Adding any / all of the
following, though, won't shift the Pragma: and Cache-Control: headers
-- they all seem to have no effect on my actual HTTP transaction, so
it's still not being cached properly:

cache.SetCacheability(HttpCacheability.Public);
cache.SetMaxAge(new TimeSpan(30, 0, 0, 0));
cache.SetExpires(DateTime.Now.AddDays(30));
cache.SetLastModifiedFromFileDependencies();
cache.SetValidUntilExpires(true);

Does anyone have any experience with setting HttpCachePolicy properties
from within an IHttpModule? Am I missing something really obvious?

If people could try to remember to cc: me on replies, as well as
sending them to this newsgroup, as I don't always remember to check
Usenet as often as I'd like.

Thanks everyone!


Owen
--
Owen Blacker
Senior Software Developer

Wheel: insight | thinking | creativity

owen.blacker (AT) wheel (DOT) co.uk www.wheel.co.uk


Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.