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.
Store data into Cache in ASP.NET MVC in ASP.NET MVC Above action method first checks for the null value in HttpContext. Cache[“MyDate”] and it its null then saves current date in the Cache. Next line simply keep the data from the Cache into ViewBag. DateTime.
In ASP.NET MVC, there is an OutputCache filter attribute that you can apply and this is the same concept as output caching in web forms. The output cache enables you to cache the content returned by a controller action. Output caching basically allows you to store the output of a particular controller in the memory.
Any (Default)- Content is cached in three locations- the Web Server, any proxy Servers and the Web Browser. Client- Content is cached on the Web Browser. Server- Content is cached on the Web Server. ServerAndClient- Content is cached on the Web Server and the Web Browser.
Donut caching is a server-side caching technique in which the entire page is cached, except for small portions that remain dynamic.
"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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With