什么时候不应该在 Webforms 中设置 @OutputCache 共享属性?

发布于 2024-10-10 04:48:03 字数 657 浏览 0 评论 0原文

阅读 MSDN 中的 @OutputCache 文档我注意到 Shared 属性

文档说:

共享

布尔值,决定用户控制输出是否可以

与多个页面共享。这 默认为 false。了解更多 信息,请参阅备注部分。

备注说:

如果将共享属性设置为 true,缓存的用户控制输出可以 可通过多个 Web 表单访问 页。如果不将其设置为 true, 默认行为是缓存一个 用户控制输出的版本 包含该用户的每个页面 控制。您可能可以保存 大量的内存 启用共享属性。为了 更多信息,请参阅缓存部分 ASP.NET 页面的一部分。

所以我开始相信,通常情况下,对于将在不同页面中精确呈现的控件,应该将其设置为 true,以节省缓存内存。

问题是......什么时候我应该Shared设置为true?

Reading the @OutputCache documentation in MSDN I have noticed the Shared attribute

Doc says:

Shared

A Boolean value that determines whether user control output can be

shared with multiple pages. The
default is false. For more
information, see the Remarks section.

Remarks says:

If you set the Shared attribute to
true, cached user control output can
be accessed by multiple Web Forms
pages. If you do not set it to true,
the default behavior is to cache one
version of user control output for
each page that contains that user
control. You can potentially save a
significant amount of memory by
enabling the Shared attribute. For
more information, see Caching Portions
of an ASP.NET Page.

So I'm starting to believe that normally this should be set to true for controls that are gonna be rendered exactly in different pages in order to save cache memory.

The question is... when should I not set Shared to true?

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

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

发布评论

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

评论(1

三生路 2024-10-17 04:48:03

当不同页面的控制输出不同时,不应使用它。

假设您有一个控件,其输出会根据人们浏览站点的方式而变化(面包屑控件) - 您希望跨页面共享该控件。

You should not use it when the control output is different across different pages.

Say you have a control whose output changes depending on how one navigates your site (breadcrumb control) - you do not want that to be shared across pages.

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