新手入門 ASP.NET2.0緩衝技術

來源:互聯網
上載者:User

新手入門 ASP.NET2.0緩衝技術 
2007-12-13 09:43 來源:部落格網  
 
 
ASP.NET2.0提供如下緩衝方式:

Output Caching

Fragment Caching

Data Cache

SQL Cache

Cache Configuration

1. Output Caching:

當一個網頁被頻繁訪問時,我們可以把把整個網頁緩衝起來提高效率,當使用者在此訪問時,被格式化好的HTML被直接送到用戶端。

<%@ OutputCache Duration="120" VaryByParam="none" %>

2. 參數緩衝:

根據使用者的請求來產生頁面,使用者的請求只有有限的幾種組合,我們根據參數該表緩衝內容。

<%@ OutputCache Duration="120" VaryByParam="state" %>

<%--<a href="Default.aspx?state=CA"></a>--%>

3. 硬碟緩衝:

預設情況下Output Cache會緩衝到硬碟上,我們可通過修改diskcacheenable的屬性設定其是否緩衝,還可以通過在web config裡配置快取檔案的大小。

4. 頁面片段緩衝:

頁面上部分內容根據請求動態更新,大部分能容被緩衝。(如果多個控制項需要緩衝,可做成一個使用者控制項)

<%@OutputCache Duration="120" VaryByControl="ControlID" %>

<center><img src="http://myarticle.enet.com.cn/images/2007/1213/1197510156064.jpg" border="0" alt="新手入門 ASP.NET2.0緩衝技術"/></center>

5. Cache Data :

建議開啟硬碟緩衝,緩衝時間設的稍長一點,因為IO的開銷

DataSet ds=new DataSet();

ds = Cache["restaurant"];

if (ds == null)

{

ds = resDataSet;

Cache["restaurant"] = ds;

}

6. SQL Dependency

設定資料庫伺服器的sql緩衝,然後在頁面引用

<center><img src="http://myarticle.enet.com.cn/images/2007/1213/1197510159540.jpg" border="0" alt="新手入門 ASP.NET2.0緩衝技術"/></center>

7. Cache Configuration (減少重複定義)

a .web.config定義

<center><img src="http://myarticle.enet.com.cn/images/2007/1213/1197510164294.jpg" border="0" alt="新手入門 ASP.NET2.0緩衝技術"/></center>

b. 頁面調用

<%@ OutputCache CacheProfile="CacheFor60Seconds" VaryByParam="name" %>
<table width="90%" border="0" cellpadding="0" cellspacing="0" align="center">
<tr> <td><b>熱門推薦</b>:</td>
<td><a href="http://www.enet.com.cn/article/2007/1210/A20071210942740.shtml" target="_blank"><font size=2 color=red>無敵命令 刪除不能刪除的檔案
</font></a></td>
<td><a href="http://www.enet.com.cn/article/2007/1211/A20071211943925.shtml" target="_blank"><font size=2 color=red>不怕被攻擊 Windows防黑技巧七招</font></a></td>
</tr></table>
 
 
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.