There can be no Triumph without Loss,No Victory without Suffering,No Freedom without Sacrifice.
All you have to decide is what to do with the time that is given to you.
Get busy Living, or Get busy Dying?
  首页 | 留言给我 | 订阅 Rss | CLI | 黄白之恋 Posts:158   Hits: 5074018    Comments: 173    
 日历归档
<<  <  2024 - 04  >  >>
SuMoTuWeThFrSa
 123456
78910111213
14151617181920
21222324252627
282930
 About Me
 Name: ZhangSichu
 Sex: Male
 Age: 32
 Email: ZhangSichu@gmail.com
 MSN: ZhangSichu@hotmail.com
 Home: ZhangSichu.com
 WeiBo: weibo.com/zhangsichu
 个人推荐
 分类归档
  ·C++/C(5)  RSS
  ·软件工程(1)  RSS
  ·杂事/随感(26)  RSS
  ·.Net/Java(30)  RSS
  ·面向对象程序设计(5)  RSS
  ·汇编/破解(0)  RSS
  ·平面设计(3)  RSS
  ·SQL(5)  RSS
  ·COM/COM+(2)  RSS
  ·Web开发(81)  RSS
 My Friends
Back Forward Refresh Home 2024年4月25日 星期四 RSS CLI Mine Sweeper. In Javascript.

  Asp.net/2.0 性能/Caching 学习
字体大小 [ ]

1.注意使用Page.IsPostBack确定用户是否是第一次进入页面,确定是否需要载入数据。
void Page_Load(Object sender, EventArgs e) {
// ...set up a connection and command here...
if (!Page.IsPostBack) {
String query = "select * from Authors where FirstName like %JUSTIN%";
myCommand.Fill(ds, "Authors");
myDataGrid.DataBind();
}
}
void Button_Click(Object sender, EventArgs e) {
String query = "select * from Authors where FirstName like %BRAD%";
myCommand.Fill(ds, "Authors");
myDataGrid.DataBind();
}

2.Asp执行的过程:Page_Lode ->Properties Change(e.g:ListBox:Auto Postback)->Action()(ButtonClick)。

3.关闭不必要的Session状态<%@ Page EnableSessionState="false" %> 这个page 不存取Session。注意使用Server Control不必要时可以不使用Server Control不必要时可以关闭ViewState
<asp:datagrid EnableViewState="false“ runat="server"/>
<%@ Page EnableViewState="false" %>
Application 是全局的每一个用户都一样。
Session 每一个用户一套。
ViewState 一个用户不同的Control,ViewState不同。ViewState 针对某个用户某个页面某个Control的State是ViewVtate。

4.不用 Exception来控制程序流程。Exception的开销很大。

5.使用存储过程数据访问,只读数据访问不要使用DataSet,使用SqlDataReader代替DataSet,SqlDataReader是read-only, forward-only。

6.关闭ASP.NET的Debug模式

7.使用ASP.NET Output Cache缓冲数据。

8.页面缓冲
<%@OutputCache%> 参数Duration(过期时间) VaryByParam()(get/post) 片断缓冲VaryByControl use控件缓冲VaryByParam Cache for each combination of specified parameters. 多参数时,参数的每一个排列组合都会纪录一个缓冲。

9.数据缓冲
Cache.Insert("MyData", Source, new CacheDependency(Server.MapPath("authors.xml")));
//CacheDependency 是一个很有用的东西,数据依赖缓冲
Cache.Insert("MyData", Source, null,DateTime.Now.AddHours(1), TimeSpan.Zero);
Cache.Insert("MyData", Source, null, DateTime.MaxValue,TimeSpan.FromMinutes(20));

10.IIS 自身设定缓存,让IIS自己来决定缓存多少。

11.在Asp的控件中有一个Substitution控件,这个控件是一个Html头的容器,使用这个容器可以封装一个Html的请求。如果想在一个已经使用了output-caching的页面里显示动态的内容就需要使用这个Substitution控件。
//Substitution定义
<asp:Substitution ID="Substitution1" runat="server" MethodName="GetCurrentDate" />
//页面中Call back 的方法 注意:这个方法必须是静态方法
<script runat="server">
Shared Function GetCurrentDate(ByVal context As HttpContext) As String
Return Now.ToString()
End Function
</script>

12.<%@ OutputCache Duration="60" VaryByParam="none" %>可以在一个控件里设置 OutputCache, 那么在那个用户控件就别自动的缓存了,当这个控件别托拽到aspxPage上时,这个控件自身就缓存了。

13.System.Web.Caching.Cache存入需要缓存的内容。

14.Aspnet_regsql.exe
Aspnet_regsql.e –S “.\SQLExpress” –E –d”pubs” –ed
aspnet_regsql -S slhsql2005-1 -E -d pubs -ed
aspnet_regsql -S slhsql2005-1 -E -d pubs -t authors –et
<%@OutputCache duration =”999999” sqlDependency=”pubs:Authors” VaryByParam=”none” %>
在 WebConfig中的定义:
    <caching>
      <sqlCacheDependency enabled="true" pollTime="1000" >
        <databases>
          <add name="pubs" connectionStringName="pubsConnectionString" />
        </databases>
      </sqlCacheDependency>
    </caching>

15.在页面里定义<%@ OutputCache CacheProfile="CacheFor60Seconds" VaryByParam="name" %>这里的CacheFor60Seconds是一个在WebConfig中定义好一个outputCacheSettings/outPutCacheProfiles。
    <caching>
      <outputCache>
        <diskCache enabled="true" maxSizePerApp="2" />
      </outputCache>
      <outputCacheSettings>
        <outputCacheProfiles>
          <add name="CacheFor60Seconds" duration="60" />
        </outputCacheProfiles>
      </outputCacheSettings>
    </caching>

16.在DataSource中使用缓存<asp:SqlDataSource
ID="SqlDataSource1"
EnableCaching="True"
CacheDuration="300"
ConnectionString="<%$ ConnectionStrings:pubsConnectionString %>"
SelectCommand="SELECT * FROM [titles]"
Runat="server" OnSelecting="SqlDataSource1_Selecting" />
DataSource 这个缓存非常有用 在Cache 栏目中提供很多设置选项来控制DataSource的Cache
  Posted @ 7/5/2006 11:39:15 AM | Hits (74130) | Comment (0

  Post Comment
标题 *
作者 *
密码 记住我
评论 *
    


Stable in Firefox 1.5 2.0Stable in IE6 IE7Stable in MozillaStable in Netscape
ZhangSichu.com V0.1.7507
Powered By ZhangSichu
Copyright © ZhangSichu
Download ZhangSichu.com source code. Download source code