Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I 'donut cache' in ASP.NET MVC for something more than a date

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.

like image 706
Simon_Weaver Avatar asked May 15 '09 01:05

Simon_Weaver


People also ask

How can store data in cache in ASP.NET MVC?

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.

How can use cache in ASP.NET MVC?

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.

What are the different caching techniques available in .NET MVC?

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.

What is donut caching?

Donut caching is a server-side caching technique in which the entire page is cached, except for small portions that remain dynamic.


1 Answers

"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.

like image 185
eu-ge-ne Avatar answered Oct 24 '22 14:10

eu-ge-ne