开发者

Is Cache Substitution working in ASP.NET MVC 2?

开发者 https://www.devze.com 2022-12-18 15:28 出处:网络
After upgrading an application from ASP.NET MVC 1 to ASP.NET MVC 2 RC cache substitution has stopped working.

After upgrading an application from ASP.NET MVC 1 to ASP.NET MVC 2 RC cache substitution has stopped working.

This is my action:

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

This is the Substitute extensions:

public static object Substitute(this HtmlHelper html, MvcCacheCallback cb)
{
    html.ViewContext.HttpContext.Response.WriteSubstitution(
        c => cb(ne开发者_开发技巧w HttpContextWrapper(c)));
    return null;
}

And this is my view:

<%@ 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 substitution does not work, it just shows the time when the page was initially rendered. That was working in ASP.NET MVC 1.0!!

Any ideas?

Thanks


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


This is specification, written at release note.

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

Due to changes in the rendering behavior of MVC view engines, the Html.Substitute helper method does not work and has been removed.


This is also a bit late, but I've been working to develop a library that can bring post cache substitution back to Asp.Net MVC with performance as a primary concern. It's capable of rendering an output cached page with around 20 or so complex substitutions on one of the sites I maintain in around 6ms to 10ms.

We've been delaying upgrading most of our projects past MVC 1 because of how post cache substitution broke past MVC 2. I've been working on this to allow us to upgrade the base our code is built on.

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

0

精彩评论

暂无评论...
验证码 换一张
取 消