日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
ASP.NET數(shù)據(jù)緩存機(jī)制淺析

ASP.NET數(shù)據(jù)緩存機(jī)制主要是什么呢?讓我們開始我們的講解:

◆頁輸出緩存:保存頁處理輸出,下次重用所保存的輸出

◆應(yīng)用程序緩存:允許緩存所生成的數(shù)據(jù),如DataSet

㈠ASP.NET數(shù)據(jù)緩存頁輸出緩存

1、ASP.NET數(shù)據(jù)緩存頁輸出緩存的幾中形式

① ﹤%@   OutputCache   Duration= "60 "   VaryByParam= "None "   Location= "Any "%﹥

Location指定在哪個地方緩存,Any任何地方都緩存。

60秒以內(nèi)看到的都是一樣的了。

②還可在配置文件里寫,然后在頁面調(diào)用配置文件的緩存名稱。

③用編程的方式:

 
 
 
  1. Response.Canche.SetExpires(DateTime.Now.AddSeconds(3)); 
  2. Response.Canche.SetCacheabiliy(HttpCacheability.Public); 
  3. Response.Canche.SetValidUntilExpires(true);

 相當(dāng)于:

 
 
 
  1. Public   =﹥   Any 
  2. Private   =﹥   Client 
  3. NoCache   =﹥   None 
  4. Server   =﹥   Server 
  5. ServerAndPrivate   =﹥ ServerAndClient 

2、ASP.NET數(shù)據(jù)緩存使用文件依賴項(xiàng)緩存頁輸出

產(chǎn)生背景:有時候,可能需要在文件發(fā)生更改時從輸出緩存中移除某一項(xiàng)。就是說文件改了以后緩存立即失效。

 
 
 
  1. string   filepath   =   Server.MapPath( "TextFile1.txt "); 
  2. Response.AddFileDependency(filepath);//添加緩存依賴項(xiàng) 
  3. Response.Cache.SetExpires(DateTime.Now.AddSeconds(60)); 
  4. Response.Cache.SetCacheability(HttpCacheability.Public); 
  5. Response.Cache.SetValidUntiExpires(true); 

3、ASP.NET數(shù)據(jù)緩存緩存多個版本

①使用請求的瀏覽器對頁的各個版本進(jìn)行緩存

 
 
 
  1. ﹤%@OutputCache   Duration= "10 "   VaryByParam= "None "   VaryByCustom= "browser "%﹥ 

②使用參數(shù)對頁的各個版本進(jìn)行緩存

 
 
 
  1. ﹤%@OutputCache   Duration= "60 "   VaryByParam= "City "%﹥ 

這個調(diào)試可以在url后加QueryString

如:...url?City=shanghai

程序里得到這個上海然后再做其他的操作,這個時候如果參數(shù)傳的還是shanghai它就不會在走到程序里了。

4、ASP.NET數(shù)據(jù)緩存動態(tài)更新緩存頁的部分,有三種方法可以實(shí)現(xiàn)部分不緩存

①已聲明方式使用Substitution控件

 
 
 
  1. ﹤asp:Substitution   ID= "Substitution1 "   runat= "server "   MethodName= "GetCurrentDateTime "   /﹥ 
  2. public   static   string   GetCurrentDateTime(HttpContext   context) 
  3. return   DateTime.Now.ToString(); 
  4. //方法簽名必須和委托簽名一致 

②以編程的方式使用Substitution控件API

Response.WriteSubstitution(new   HttpResponseSubstitutionCallback(GetCurrentDateTime))

③以隱式方式使用AdRotator控件

這個控件永遠(yuǎn)都是不緩存的

㈡ASP.NET數(shù)據(jù)緩存SQL   Server依賴的緩存,非常之有用

當(dāng)表數(shù)據(jù)發(fā)生改變就清除緩存

1、ASP.NET數(shù)據(jù)緩存為SQL   Server啟用緩存通知

 
 
 
  1. aspnet_regsql.exe   -S   ﹤Server﹥   -U   ﹤Username﹥   -P   ﹤Password﹥ 
  2. -ed   -d   Northwind   -et   -t   Employees 

Server:服務(wù)器

Username:用戶名

Password:密碼

Northwind:數(shù)據(jù)庫

Employees:表

2、ASP.NET數(shù)據(jù)緩存為緩存功能配置網(wǎng)頁

 
 
 
  1. ﹤%@OutputCache   Duration= "3600 "   SqlDependency= "Northind:Employees "   VaryByParam= "none "%﹥ 

3、ASP.NET數(shù)據(jù)緩存在Web.config文件中設(shè)置緩存配置

 
 
 
  1. ﹤caching﹥ 
  2.   ﹤sqlCacheDependency   enabled= "true "   pollTime= "1000 "﹥ 
  3.     ﹤database﹥ 
  4.       ﹤add   name= "Northind "   connectionStringName= "... "   pollTime   =   "1000 "   /﹥ 
  5.       ﹤/database﹥ 
  6.   ﹤/sqlCacheDependency﹥ 
  7. ﹤/caching﹥ 

ASP.NET數(shù)據(jù)緩存方面的內(nèi)容就向你介紹到這里,希望對你了解ASP.NET數(shù)據(jù)緩存有所幫助。


新聞標(biāo)題:ASP.NET數(shù)據(jù)緩存機(jī)制淺析
網(wǎng)頁URL:http://www.dlmjj.cn/article/cohjece.html