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.

No comments:

Post a Comment