How to set caching headers like mojoportal.com

If you have questions about using mojoPortal, you can post them here.

You may want to first review our site administration documentation to see if your question is answered there.

This thread is closed to new posts. You must sign in to post in the forums.
3/12/2012 11:20:21 AM
Gravatar
Total Posts 73

How to set caching headers like mojoportal.com

When I look at the headers for a generic page request on my site using curl, I get no response headers related to caching.  I'm on IIS6.

When I do the same for mojoportal.com, I get the following:

>curl -I http://www.mojoportal.com/
HTTP/1.1 200 OK
Cache-Control: no-cache, no-store, must-revalidate, post-check=0,pre-check=0
Pragma: no-cache

I'm considering employing the same headers on my site as a best practice, assuming these are intentional.

Any idea how I might do that on IIS6?

3/12/2012 11:35:50 AM
Gravatar
Total Posts 18439

Re: How to set caching headers like mojoportal.com

I'm not sure of any global way to do it by configuration (doesn't mean there isn't a way, I just don't know of one without researching it).

In mojoPortal CMS pages there is a page setting that determines whether browser caching is allowed and we enforce it from code that sets those headers in Default.aspx which serves the cms pages:

if (!CurrentPage.AllowBrowserCache)
{
SecurityHelper.DisableBrowserCache();
}

the code for the helper method is like this:

public static void DisableBrowserCache()
{
if (HttpContext.Current != null)
{
HttpContext.Current.Response.Cache.SetExpires(new DateTime(1995, 5, 6, 12, 0, 0, DateTimeKind.Utc));
HttpContext.Current.Response.Cache.SetNoStore();
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
HttpContext.Current.Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
HttpContext.Current.Response.Cache.AppendCacheExtension("post-check=0,pre-check=0");

}
}

Generally since we are customizing the page per user, ie showing some links (sign in, edit links etc) depending on whether they are authenticated and what roles they have it can be problematic to allow browser caching. Especially because we don't know if the client machine is shared by multiple users, with caching there would be a potential to render something incorrect from the browser cache.

Hope that helps,

Joe

3/12/2012 11:54:48 AM
Gravatar
Total Posts 73

Re: How to set caching headers like mojoportal.com

Yup, that setting does it.

Thanks!

You must sign in to post in the forums. This thread is closed to new posts.