繁体   English   中英

如何使用C#MVC和Varnish进行甜甜圈缓存?

[英]How to do donut caching with c# mvc and Varnish?

我添加到清漆配置

sub vcl_fetch {

   set beresp.do_esi = true; 

}

}

在我的mvc应用程序中,我有一个动作

<div>@* this should not be cached, I change the returned value in my DB *@
        1 @Html.Action("GetHour", "Index", new { id = 5 })
    </div>

    <div>
        2
        <esi:include>@* this should be cached *@
            @Html.Action("GetHour", "Index", new { id = 5 })
        </esi:include>
    </div>

并添加了一个请求头

Request.Headers.Add("X-Esi", "1");

但是Varnish会继续缓存整个页面。

我想念什么? 我注意到浏览器中的请求标头X-Esi不存在。 另外,上光油会正确删除<esi:include标签

使用GetHour的代码非常简单,只需从SQL Server中检索一个小数即可。

更改此:

<esi:include>@* this should be cached *@
        @Html.Action("GetHour", "Index", new { id = 5 })
    </esi:include>

为了这:

<esi:include src="/Index/GetHour/5">
          </esi:include>

并添加到Varnish default.vcl:

sub vcl_fetch {
   set beresp.do_esi = true;

  if(bereq.url ~ "/Index/GetHour"){
    set beresp.ttl = 0s;
  }
}

@ronald在上面的评论中部分回答了此问题。 还必须删除[ChildActionOnly]批注。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM