Caching in ASP.NET Dynamic Data

One question that came up at my presentation to the Maine Bytes user group this week centered around the degree to which Dynamic Data will leverage ASP.NET caching.  Given that the UI of a Dynamic Data site more or less comprises a small set of page and control templates, and it's often just the data that changes as you navigate, it would seem to be a great opportunity to cache the presentation markup.  On the other hand, the on-the-fly nature of the page generation led me to suspect that there may not be much opportunity after all.  At the time I didn't have as definitive an answer as I'd like... so I went to the source of all that is right and good -- engineering!

As explained to me, since the default templates are all wrapped in an AJAX UpdatePanel, the pages are pretty much going be re-rendered on every postback.  If you use a tool like Fiddler, you can see empirically that this indeed is the case.  Now some of the ways to avoid this is to move to more of an AJAX approach where client-processing can be leveraged more effectively, and that's a direction that the Dynamic Data team may look at as the feature matures.  In the meantime, since it's ultimately just ASP.NET Web Forms under the covers, caching techniques and strategies that are appropriate for traditional, non-Dynamic Data ASP.NET sites would still be applicable here.

Now another aspect of caching is that of the data model and its attributes.  The model *is* cached when registered via the MetaModel.RegisterContext method in the Application_Start event.  That's great in terms of performance, given how frequently the model is consulted as the site pages are generated; however, a drawback (perhaps affecting just more advanced scenarios) is that you can't modify the model dynamically (such as by using a custom metadata provider) because the cache is not refreshed once initialized.  Check out Marcin's post on that topic.