ASP.NET @OuputCache 指令“继承”

发布于 2024-09-01 03:42:17 字数 445 浏览 6 评论 0原文

正如我在之前的问题中提到的,我在网络性能方面遇到了问题站点...一些 SQL 查询正在杀死服务器。但是,正如本文标题所提到的,我查看了 OutputCache 页面指令来提高站点的性能。

不过,我遇到了有关该指令的一些问题: 1-如果我有一个 Web 用户控件,该控件在一个页面中声明了一个 OuputCache 指令,而该页面也有一个 OuputCache 指令,那么哪一个将“获胜”? 2-关于持续时间的最佳做法是什么?我也想有一个推拉窗。

感谢您的帮助,请访问 http://www.developerit.com

As I mention in an earlier question, I am having trouble with the performance of a web site... Some SQL queries are killing the server. But, as the title of this post mention, I looked at the OutputCache page directive to improve performance of the site.

Although, I came across some questions regarding this directive:
1- If I have a web-user control that declares an OuputCache directive in a page that has one too, which one will "win" ?
2- What's the best pratice regarding the duration ? I'd love to have a sliding window too.

Thanks for your help and please visit http://www.developerit.com

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

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

发布评论

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

评论(2

拍不死你 2024-09-08 03:42:17

对于两者均未缓存的请求,将创建页面和控件,然后将其添加到输出缓存中。如果页面被缓存,则无论控件是否在缓存中,都不会创建该控件 - 它的标记包含在页面的缓存副本中。如果页面未缓存而控件已缓存,则将在页面中使用控件的缓存标记。

On a request where neither are cached, both the page and the control will be created, and then added to the output cache. If the page is cached, the control will not be created, regardless of whether it's in the cache or not--its markup is contained in the cached copy of the page. If the page is not cached and the control is, the cached markup of the control will be used in the page.

笑饮青盏花 2024-09-08 03:42:17

这是一篇关于输出缓存的好文章: https://web.archive.org/web/20211020111708/https://www.4guysfromrolla.com/articles/121306-1.aspx

一般来说,您似乎正在查看页面和片段缓存。如果可以的话,您想要做的是缓存页面,因为这将为您带来最佳的性能优势。但是,如果页面上的某些区域必须根据用户动态更改,例如:您在页面顶部说“嗨{用户名}”,那么您需要查看片段缓存。

片段缓存不如页面缓存有效,因为输出必须将缓存信息和动态信息拼接在一起,但它通常仍然比没有缓存好得多!

根据页面的功能和数据库的负载来调整缓存是一门艺术,但它可以使页面加载比非缓存快很多数量级。

仅供参考 - 如果数据库查询正在杀死站点,您可能还需要考虑驯服它们和/或单独缓存它们的输出,这样您就不必继续访问数据库来获取相同的信息。

还要了解用于缓存的“varyByParam”也非常有用 - 假设您有一个包含 3 种语言的页面,您可以使用 VaryByParam 为每种语言缓存页面,只要您的 Url 是 VaryByParam 可以选择的某种语言组件向上。

哈特哈,

Here's a good article on Output caching: https://web.archive.org/web/20211020111708/https://www.4guysfromrolla.com/articles/121306-1.aspx.

Generally, you seem to be looking at Page and Fragment caching. What you want to do is cache the Page, if you can, as that will give you the best performance benefit. But, if you have regions on the page that must change dynamically per user, eg: you are saying 'Hi {username}' at the top of the page, then you need to look at Fragment caching.

Fragment caching is not as effective as page caching, since the output has to be stitched together from cached info and dynamic info, but it's usually still MUCH better than NO caching!

It's a bit of an art, to tweak the caching depending on what the page does and the load on the database, but it can make a page load many Orders of Magnitude faster than non-cached.

FYI - if the db queries are killing the site you may want to also look at taming them and/or caching their output individually, so that you don't have to keep hitting the database for the same information.

Also understand the 'varyByParam' for caching is pretty useful too - say you have a page in 3 languages, you can cache a page for each language by using the varyByParam, as long as your Url some sort of language component that the varyByParam can pick up.

HTH,
Lance

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