母版页如何页面部分缓存

把treeView做到一个用户控件里,然后设置用户控件的缓存, 或者直接把treeView放到Cache里去,我的母版页有个treeView,它是动态生成的!但是现在我每跳转一次界面,它就会去数据库查询一次!我想把它用页面部分缓存,可是不会写!也没在母版页找到<%@ OutPutCache %>,希望哪个大虾指点一二! 

问题补充:

我就是想把这个treeView缓存起来! 我这个treeView是动态的,根据权限不同生成的tree也不同!
-----------------
把treeView做到一个用户控件里,然后设置用户控件的缓存, 或者直接把treeView放到Cache里去,
-----------------

母板页不能用缓存里面的子页可以用缓存啊。
母板页只是起一个框架的作用。
加在母板页上的自定义控件页可以独立加缓存。

-----------------

ASP.NET 2.0 has added two very important improvements to the caching feature set that make it even better:

1) SQL Cache Invalidation Support - This enables you to automatically invalidate/re-generate a cached page or data structure when a database table or row it depends on is updated.  For example, you can now output cache all of your product listing pages within an e-commerce site - and make sure that anytime that their prices change in the database the pages are immediately re-generated on the next request (and do not show stale pricing data to users). 

2) Output Cache Substitution - This nifty feature enables you to implement what I sometimes call "donut caching" -- where you output cache everything on a page except for a few dynamic regions that are contained within cached regions.  This enables you to implement full page output caching more aggressively, and not have to split your pages into multiple .ascx user control files to order to implement partial page caching.  The below tip/trick tutorial explains the motivation and implementation of this feature better.

-----------------

Q: I'm having a problem with performance in my ASP.NET master page. In the debugger I see the master page runs during each postback. How do we stop the master page from running its Load event each time?

A: The MasterPage class derives from UserControl, which gives a hint as to why the master behaves this way. The master page becomes a control inside the page, and like every control in ASP.NET the master recreates itself on every postback (see Master Pages: Tips, Tricks, and Traps).

You might be able to improve the situation using some common ASP.NET performance tips:

  • Take areas of the master page that contain static content and place them into user controls. Place the user controls on the master page, and use output caching to avoid executing the code inside.
  • Check Page.IsPostBack during the master's Page_Load event handler and avoid performing unnecessary work. Use Atlas to refresh small sections of the page.
  • Evaluate the use of ViewState. If you can let controls restore themselves from ViewState you can avoid re-querying the database. The tradeoff is increased page size, so measure carefully.

-----------------

使用缓存

    只有在内容页面才可以使用如下的 directive 指定缓存:

    <%@ OutputCache Duration="10" Varybyparam="None" %>

    (这个指令让服务器在内存里缓存该页面 10 秒钟)

    如果对 Master Page 指定该指令,本身并不会引发错误。但是当他的子页面下一次来获取其 Master Page 的时候,如果这时 Master Page 已经过期,则会引发一个错误。
    所以实际上只能对子页面指定缓存。

-----------------

-----------------

http://weblogs.asp.net/scottgu/archive/2006/11/28/tip-trick-implement-donut-caching-with-the-asp-net-2-0-output-cache-substitution-feature.aspx

http://dotnetperls.com/output-caching-master-page

http://zhidao.baidu.com/question/82115557.html?fr=qrl&cid=869&index=1&fr2=query
http://forums.asp.net/p/1208256/2126713.aspx#2126713
http://www.cnitblog.com/MartinYao/articles/21775.html
 
 
原文地址:https://www.cnblogs.com/emanlee/p/1659423.html