Thursday 21 June 2007

ASP.NET Fragment Caching in MOSS

I've noticed an odd happening with fragment caching in MOSS 2007: a user control declared in a master page will not be cached but when that same user control is wrapped in a second user control and the wrapper control is declared in the master page, the wrapped control caches as expected.

Things look like this:


<%@ Register tagprefix="CustomControls" tagName="Container" src="~/UserControls/Container.ascx" %>
<%@ Register TagPrefix="CustomControls" TagName="ToCache" Src="~/UserControls/ToCache.ascx" %>
<CustomControls:Container id="container" runat="server"/>
<CustomControls:ToCache ID="toCache" runat="server"/>


<%@ Register tagprefix="CustomControls" tagName="ToCache" src="~/UserControls/ToCache.ascx" %>
<CustomControls:ToCache id="toCache" runat="server" />

The resulting HTML looks like this:

<div id=”container”>
<div id=”toCache”>... </div> // This caches
<div id=”toCache”>... </div> // This won’t cache

The ToCache.ascx user control sets a simple @OutputCache directive in the markup and I can't see anything that would limit output caching in the master page, the hosting .aspx page, or the web.config.

I haven't ripped this apart and tried it in a clean site but I'm definitely experiencing this behaviour within the context of the development environment. I know MOSS controls (and somehow enhances) output caching but I have yet to look into how this works--as far as I know, I'm using the default output caching configuration.

Update: I wonder if this has anything to do with the control being hosted in a master page instead of an aspx page layout. Slim chance...


  1. I am having the same problem, but my user control IS inside a page layout. I am wondering if MOSS overrides the OutputCache mechanism.

  2. I'm pretty sure it does, having played with the MOSS Output caching controls since I wrote this post. Caching in MOSS is actually pretty straightforward once you get into it--I'd suggest turning it on if it's not already.


Spam comments will be deleted

Note: only a member of this blog may post a comment.