ASP MVC2 中部分缓存的当前做法是什么?

发布于 2024-09-27 04:24:56 字数 828 浏览 5 评论 0原文

我的网站页面由两种内容组成。第一个在用户之间是可变的,但对于所有页面都是恒定的。第二个在用户之间是不变的,但在页面之间是可变的。这是常见的布局。将输出缓存应用于此类内容的最佳方法是什么?

据我了解, Html.Substitute 帮助器与 MVC2 渲染管道不兼容,从而消除了旧的甜甜圈缓存方式。

对每个页面使用 VaryByParam="user" 的正常输出缓存?

特异性水平会降低输出缓存的价值。在缓存输出的生命周期内,同一用户不太可能多次查看同一页面。

使用替代的 OutputCache 子系统

互联网上有多种修改 OutputCache 属性和呈现子系统以支持替换的尝试。我发现的最好的一个是 这里

然而,我发现的各种片段似乎都是非正式的实现,并且没有得到很好的支持。此外,我倾向于怀疑,如果将替换添加回 MVC2 管道是那么容易,那么它就已经完成了。

由单独缓存的多个子操作组成最终页面

操作方法不会使用 OutputCache 属性进行标记,并且将返回包含多个 Html.RenderAction 调用的视图这将提取独立缓存的内容。除了使用 RenderAction 的稍微重量级的影响之外,它还会添加额外的间接层和代码味道。

您在 MVC2 中编写独立缓存内容的体验如何?什么效果好,什么效果不好?

My website pages are composed of two kinds of content. The first is variable between users but constant for all pages. The second is constant across users, but variable between pages. This is a common layout. What is the best way to apply output caching to content like this?

As I understand it, the Html.Substitute helper is incompatible with the MVC2 rendering pipeline, eliminating the old way of donut caching.

Use normal output caching with VaryByParam="user" for every page?

The level of specificity would reduce the value of output caching. It's unlikely that the same user will view the same page very many times within the lifespan of the cached output.

Use a alternate OutputCache subsystem

There are several attempts floating around the internet that modify the OutputCache attribute and rendering subsystem to support substitution. The best one I've found is here.

However, the various snippets I've found seem to be informal implementations, and aren't well supported. Additionally, I'm inclined to suspect that if it were that easy to add substitution back into the MVC2 pipeline, it would've been done.

Compose the final page from several child actions which are individually cached

The action method would not be flagged with an OutputCache attribute, and would return a view which contains several Html.RenderAction invocations which would pull in independently cached content. Aside from the slightly heavyweight implications of using RenderAction, it would add an extra layer of indirection and a code smell.

What is your experience with composing independently cached content in MVC2? What's worked well and what hasn't?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

泪意 2024-10-04 04:24:56

请查看此问题以及信息stackoverflow 如何做到这一点可以帮助您。

Please take a look at this question ans also info how stackoverflow does this can help you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文