Tuesday, 6 May 2008

Make 'Exires' Go Away

Yesterday I posted about the useless 'Exires' [sic] header moss emits with content served from the content database under the default configuration. "Shame on you MOSS!" was shouted with just cause.

Nevertheless, I've found a fairly easy way to make 'Exires' go away and configure MOSS to emit better cache headers. It's pretty simple and while it will cost you a bit of disk space it should also save on roundtrips to the database server... all you need to do is enable the MOSS BLOB cache (aka Disk Cache).

The BLOB cache is turned off by default (for some reason) but when enabled it'll grab a copy of content database resources on the first request and cache them on disk for faster access down the road. Not only that, but, despite the name, the BLOB cache makes MOSS smart enough to emit good Cache-Control headers with your content.

The BLOB cache is configured through the web.config at the web application level, which leads me to believe you won't be able to set different max-age values for different types of content or different content groupings (let's say you want your .css and .js files cached with a different max-age value--or none at all--from the served with your images). If you're used to doing this with the content expiration mechanism in IIS at the folder or item level you may be out of luck here.

Enabling the BLOB Cache is ridiculously easy. Dig into your site's web config and find the BlobCache element (you'll need to do this on all related sites--i.e. anonymous and authenticated if you're running both on the same server). Set the enabled attribute to "true" and you're set. You may additionally want to modify the location where MOSS stores the BLOB data (i.e. a non-system disk), add extra file types to those already configured, and add a max-age="3600" attribute. The max-age attribute will be included with the Cache-Control header and is defined in seconds. Be careful with this one because if you set it to too large a value, your content will cached for the entire duration unless users clear their browser caches. Finally, the maxSize attribute defines the maximum size of the BLOB cache in gigabytes.


<BlobCache location="D:\MOSS\Cache\Consumer" path="\.(gifjpgpngswfcssjs)$" maxSize="1" max-age="3600" enabled="true" />

MOSS instruments the BLOB cache using performance counters you can access in Performance Monitor to determine cache health, turnover, etc.

If you get the BLOB cache working you should also consider reviewing the MOSS Output Cache. I'll save the details for another post but this cache extends ASP.NET output caching and deals solely with page content.

Monday, 5 May 2008

MOSS 'Exires' Header

Dear Microsoft,

What is an "Exires" header? I know what an "ExPires" header is but I have a feeling none of us (not even IE) know what to do with Exires.

Sometimes you've really got to wonder whether MOSS went through any form of QA whatsoever (and our system administrator often asks that exact question). Below is a set of typical HTTP response headers for a file requested from MOSS.

HTTP/1.1 200 OKConnection: Keep-Alive
Content-Length: 453
Date: Mon, 05 May 2008 04:44:34 GMT
Content-Type: image/gif
ETag: "{E4BBF3CA-94E3-44CB-A5CF-DD38E3330E11},3"
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
MicrosoftSharePointTeamServices: 12.0.0.6219
Last-Modified: Wed, 19 Dec 2007 05:52:22 GMT
ResourceTag: rt:E4BBF3CA-94E3-44CB-A5CF-DD38E3330E11@00000000003
Exires: Sun, 20 Apr 2008 04:44:34 GMT
Cache-Control: private,max-age=0
Public-Extension: http://schemas.microsoft.com/repl-2

Note the useless Exires header. Without the extra 'p' this header is going to float right through any caches and will be ignored by the user agent. Not only that, but Exires is pumped out with most MOSS-based resource--that is any resource delivered from the MOSS content database (images, CSS, etc) excluding pages. Due to their size, images are great candidates for caching; likewise for the number of smaller files, like CSS and JavaScript, that otherwise clog up your page load times.