How do I 'donut cache' in ASP.NET MVC for

2019-04-30 01:54发布

All the examples for donut caching I've seen are just like this :

 <%= Html.Substitute( c => DateTime.Now.ToString() )%>

Thats fine if I just want the date, but what other options are there?

I know there is a delegate 'MvcSubstitutionCallback' which has the following signature :

 public delegate string MvcSubstitutionCallback(HttpContextBase httpContext); 

but RenderAction and RenderPartial returns void so i cant just return them from the delegate method. How can I effectively use this callback for more complex situations.

I've looked at both of Phil Haacked's articles here and here, but neither seems to do exactly what I want.

4条回答
甜甜的少女心
2楼-- · 2019-04-30 02:09

This article might be helpful: http://www.asp.net/Learn/mvc/tutorial-19-cs.aspx (Adding Dynamic Content to a Cached Page in ASP.NET MVC)

查看更多
放我归山
3楼-- · 2019-04-30 02:10

"Donut Caching" means using Response.WriteSubstitution method. If you look at MVC source you will see that System.Web.Mvc.Html.RenderPartialExtensions.RenderPartial method is using Response.Output (HtmlHelper.cs, line 277 - last line in 'RenderPartialInternal' method) - so you need create your own html helpers for handling more complex situations.

查看更多
beautiful°
5楼-- · 2019-04-30 02:32

Note that while this did work in Mvc 1.0, it no longer does in Mvc 2.0. See here: http://haacked.com/archive/2008/11/05/donut-caching-in-asp.net-mvc.aspx

查看更多
登录 后发表回答