Does Cache Substitution work in ASP.NET MVC 2?

After updating the application from ASP.NET MVC 1 to ASP.NET MVC 2, reloading the RC cache stopped working.

This is my action:

[OutputCache(Duration = 30, VaryByParam = "none")] public ActionResult CacheTest1() { return View("CacheTest"); } 

These are replacement extensions:

 public static object Substitute(this HtmlHelper html, MvcCacheCallback cb) { html.ViewContext.HttpContext.Response.WriteSubstitution( c => cb(new HttpContextWrapper(c))); return null; } 

And this is my opinion:

 <%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>CacheTest</title> </head> <body> <div> Date: <%=DateTime.Now.ToString() %> Substitute: <%=Html.Substitute(c => DateTime.Now.ToString()) %> Response.WriteSubstitution: <% Response.WriteSubstitution(c => DateTime.Now.ToString()); %> </div> </body> </html> 

The page is cached for a minute, and the substitution does not work, it just shows the time when the page was originally displayed. This worked in ASP.NET MVC 1.0!

Any ideas?

thanks

+4
source share
3 answers

A bit late, but replacing the output cache is available in Moth , which offers support for both MVC 2 and MVC 3.

+3
source

This is a specification written in a release note.

Html.Substitute helper method in MVC Futures is no longer available

Due to changes in the rendering behavior of MVC viewers, the Html.Substitute helper method did not work and was deleted.

+2
source

This is also a bit late, but I worked on creating a library that could lead to replacing the post cache back to Asp.Net MVC with primary tasks. It can display a cached page with about 20 or so complex replacements on one of the sites that I support, ranging from 6 ms to 10 ms.

We delayed the updating of most of our projects over the past MVC 1 due to the fact that after replacing the MVC-2, the mail cache was replaced. I worked on this so that we can update the base on which our code is built.

If anyone is still looking for a workaround for this problem, feel free to check out my MvcSupplantCaching project! :)

0
source

Source: https://habr.com/ru/post/1300053/


All Articles