国产片侵犯亲女视频播放_亚洲精品二区_在线免费国产视频_欧美精品一区二区三区在线_少妇久久久_在线观看av不卡

服務(wù)器之家:專注于服務(wù)器技術(shù)及軟件下載分享
分類導(dǎo)航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術(shù)|正則表達(dá)式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務(wù)器之家 - 編程語言 - ASP.NET教程 - CreateOutputCachedItemKey 緩存key的創(chuàng)建

CreateOutputCachedItemKey 緩存key的創(chuàng)建

2019-10-11 10:58asp.net教程網(wǎng) ASP.NET教程

有關(guān)OutputCache的相關(guān)資料大家可以查看 OutputCacheProvider OutputCache的一點(diǎn)點(diǎn)認(rèn)識(shí) ,我們還是復(fù)習(xí)一下OutputCache內(nèi)容

有關(guān)OutputCache的相關(guān)資料大家可以查看 OutputCacheProvider OutputCache的一點(diǎn)點(diǎn)認(rèn)識(shí) ,我們還是復(fù)習(xí)一下OutputCache內(nèi)容,OutputCache 的處理是在OutputCacheModule類中注冊(cè)ResolveRequestCache、UpdateRequestCache這2個(gè)方法,一個(gè) 用于獲取一個(gè)用于設(shè)置緩存。緩存內(nèi)容分為兩部分,一部分為緩存策略CachedVary,一部分為緩存數(shù)據(jù)CachedRawResponse,一個(gè)頁(yè)面 緩存策略只有一個(gè)CachedVary,但是它卻可以有多個(gè)緩存內(nèi)容CachedRawResponse。緩存內(nèi)容的獲取和設(shè)置主要是依賴于HttpResponse的GetSnapshot() UseSnapshot(HttpRawResponse rawResponse, bool sendBody)方法。一般我們的緩 存都是要占用存儲(chǔ)空間的盡量減少緩存內(nèi)容的副本是非常重要的,那么我們現(xiàn)在就來看看緩存key是如何創(chuàng)建的,key的創(chuàng)建取決于 CreateOutputCachedItemKey方法。CreateOutputCachedItemKey方法的內(nèi)容還是比較復(fù)雜的,現(xiàn)在讓我們一 起來看看它的具體實(shí)現(xiàn)吧。 

CreateOutputCachedItemKey方法又是如何調(diào)用的了,創(chuàng)建緩存策略key的代碼:this.CreateOutputCachedItemKey(context, null);創(chuàng)建緩存key的代碼:this.CreateOutputCachedItemKey(context, cachedVary)區(qū)別就在于參數(shù)CachedVary 的值一個(gè)為null,一個(gè)是真正的CachedVary 實(shí)例。我這里的代碼是通過Reflector.exe反編譯得到,感覺和真實(shí)的代碼有點(diǎn)差別,不過邏輯上是一樣的。 
我還是以一個(gè)實(shí)際的例子來變解析邊說明,我這里是用asp.net mvc建立的一個(gè)demo。請(qǐng)求url:http://localhost:7503/Home/index 那么path就應(yīng)該是:Home/index 
首先我們的可以需要區(qū)分我們的請(qǐng)求是Get還是Post,Post以a1打頭,否則已a(bǔ)2打頭,緊接著追加當(dāng)前的Path: 

復(fù)制代碼代碼如下:


if (verb == HttpVerb.POST) 

builder = new StringBuilder("a1", path.Length + "a1".Length); 

else 

builder = new StringBuilder("a2", path.Length + "a2".Length); 

builder.Append(CultureInfo.InvariantCulture.TextInfo.ToLower(path)); 


到這個(gè)時(shí)候我們的緩存策略key及確定的,我這里的策略key為:a2/home/index 
如果我們的cachedVary不為null則繼續(xù)執(zhí)行: 

復(fù)制代碼代碼如下:


for (int i = 0; i <= 2; i++) 

int num; 
string[] array = null; 
NameValueCollection serverVarsWithoutDemand = null; 
bool flag = false; 
switch (i) 

case 0: 
builder.Append("H"); 
array = cachedVary._headers; 
if (array != null) 

serverVarsWithoutDemand = request.GetServerVarsWithoutDemand(); 

break; 
case 1: 
builder.Append("Q"); 
array = cachedVary._params; 
if (request.HasQueryString && ((array != null) || cachedVary._varyByAllParams)) 

serverVarsWithoutDemand = request.QueryString; 
flag = cachedVary._varyByAllParams; 

break; 
default: 
builder.Append("F"); 
if (verb == HttpVerb.POST) 

array = cachedVary._params; 
if (request.HasForm && ((array != null) || cachedVary._varyByAllParams)) 

serverVarsWithoutDemand = request.Form; 
flag = cachedVary._varyByAllParams; 


break; 

if (flag && (serverVarsWithoutDemand.Count > 0)) 

array = serverVarsWithoutDemand.AllKeys; 
num = array.Length - 1; 
while (num >= 0) 

if (array[num] != null) 

array[num] = CultureInfo.InvariantCulture.TextInfo.ToLower(array[num]); 

num--; 

Array.Sort(array, InvariantComparer.Default); 

if (array != null) 

num = 0; 
int length = array.Length; 
while (num < length) 

string str = array[num]; 
if (serverVarsWithoutDemand == null) 

varyByCustomString = "+n+"; 

else 

varyByCustomString = serverVarsWithoutDemand[str]; 
if (varyByCustomString == null) 

varyByCustomString = "+n+"; 


builder.Append("N"); 
builder.Append(str); 
builder.Append("V"); 
builder.Append(varyByCustomString); 
num++; 



這段代碼說白了就是給key值追加HQF3個(gè)字符,這個(gè)循環(huán)首先處理服務(wù)器的數(shù)據(jù), 
array = cachedVary._headers; 
serverVarsWithoutDemand = request.GetServerVarsWithoutDemand(); 
其次是處理QueryString數(shù)據(jù): 
array = cachedVary._params; 
serverVarsWithoutDemand = request.QueryString; 
最后處理Form數(shù)據(jù) 
array = cachedVary._params; 
serverVarsWithoutDemand = request.Form; 
serverVarsWithoutDemand是NameValueCollection 類型的數(shù)據(jù),這里循環(huán)serverVarsWithoutDemand里面的每個(gè)key,每個(gè)key對(duì)應(yīng)的追加字符串為N+key+V+value,如果value是null則從新賦值為“+n+”,可以看見不同的請(qǐng)求這里的key及有所不同了。在QueryString和Form時(shí)這里的serverVarsWithoutDemand的取值與 
cachedVary._varyByAllParams有關(guān),cachedVary的創(chuàng)建是在OutputCacheModule 的OnLeave方法中: 
vary = new CachedVary(varyByContentEncodings, varyByHeaders, varyByParams, varyByAllParams, currentSettings.VaryByCustom); 
varyByAllParams的取值如下: 

復(fù)制代碼代碼如下:


bool varyByAllParams = false; 
if (varyByParams != null) 

varyByAllParams = (varyByParams.Length == 1) && (varyByParams[0] == "*"); 


可見varyByAllParams基本都是false,只有varyByParams有且緊有一個(gè)元素并且為*時(shí),varyByAllParams才為true,varyByAllParams為false時(shí)這里的serverVarsWithoutDemand取值為GetServerVarsWithoutDemand方法,與我們的QueryString、Form3沒什么關(guān)系。GetServerVarsWithoutDemand()方法大家可能都不怎么熟悉,我們來看看它的定義: 

復(fù)制代碼代碼如下:


internal NameValueCollection GetServerVarsWithoutDemand() 

return this.GetServerVars(); 


對(duì)這個(gè)方法不了解不要緊,我們有一個(gè)ServerVariables(獲取 Web 服務(wù)器變量的集合)屬性和他相似: 

復(fù)制代碼代碼如下:


public NameValueCollection ServerVariables 

get 

if (HttpRuntime.HasAspNetHostingPermission(AspNetHostingPermissionLevel.Low)) 

return this.GetServerVars(); 

return this.GetServerVarsWithDemand(); 


其中GetServerVarsWithDemand方法也是調(diào)用GetServerVars方法。現(xiàn)在serverVarsWithoutDemand的數(shù)據(jù)我們也搞清楚了。 
builder.Append("C"); 接下來在追加字符C 
接下來我們?cè)撎幚砭彺鎋varyByCustom的配置了 

復(fù)制代碼代碼如下:


if (cachedVary._varyByCustom != null) 

builder.Append("N"); 
builder.Append(cachedVary._varyByCustom); 
builder.Append("V"); 
try 

varyByCustomString = context.ApplicationInstance.GetVaryByCustomString(context, cachedVary._varyByCustom); 
if (varyByCustomString == null) 

varyByCustomString = "+n+"; 


catch (Exception exception) 

varyByCustomString = "+e+"; 
HttpApplicationFactory.RaiseError(exception); 

builder.Append(varyByCustomString); 


這個(gè)方法很好明白,如果_varyByCustom不為null那么我們就追加N+key+V+value格式的字符。其中key就是_varyByCustom字符串,value是調(diào)用context.ApplicationInstance.GetVaryByCustomString(context, cachedVary._varyByCustom)得到的value,如果value值為null,則設(shè)置為“+n+” builder.Append("D"); 

復(fù)制代碼代碼如下:


if (((verb == HttpVerb.POST) && cachedVary._varyByAllParams) && (request.Form.Count == 0)) 

int contentLength = request.ContentLength; 
if ((contentLength > 0x3a98) || (contentLength < 0)) 

return null; 

if (contentLength > 0) 

byte[] asByteArray = ((HttpInputStream) request.InputStream).GetAsByteArray(); 
if (asByteArray == null) 

return null; 

varyByCustomString = Convert.ToBase64String(MachineKeySection.HashData(asByteArray, null, 0, asByteArray.Length)); 
builder.Append(varyByCustomString); 


這段代碼主要是給key追加一個(gè)字符D,然后在處理Post的請(qǐng)求(非表單request.Form.Count == 0)把請(qǐng)求的內(nèi)容(字節(jié))轉(zhuǎn)化為字符追加到key中,一般的http很少會(huì)發(fā)生此情況,典型的是HttpWebRequest發(fā)生的Post請(qǐng)求會(huì)觸發(fā)。 

復(fù)制代碼代碼如下:


builder.Append("E"); 
string[] strArray2 = cachedVary._contentEncodings; 
if (strArray2 != null) 

string httpHeaderContentEncoding = context.Response.GetHttpHeaderContentEncoding(); 
if (httpHeaderContentEncoding != null) 

for (int j = 0; j < strArray2.Length; j++) 

if (strArray2[j] == httpHeaderContentEncoding) 

builder.Append(httpHeaderContentEncoding); 
break; 




這段代碼首先給key追加一個(gè)字符E,然后最佳ContentEncoding,ContentEncoding的取值為 context.Response.GetHttpHeaderContentEncoding()并且在緩存策略中的 _contentEncodings存在才追加。 
到現(xiàn)在為止我們的CreateOutputCachedItemKey方法講完了,緩存策略的key沒什么說的,與Http請(qǐng)求方式Get和Post、Request的Path屬性有關(guān)。但是緩存數(shù)據(jù)的key有關(guān)對(duì)象: 
(1)與我們的_headers有關(guān),即配置中的 VaryByHeader屬性有關(guān),VaryByHeader取值不同,key則不同 
(2)與_varyByAllParams有關(guān),當(dāng)它為true時(shí),實(shí)際上就是與 request.QueryString有關(guān),如果此請(qǐng)求是Post則還與request.Form有關(guān);_varyByAllParams默認(rèn)為 false,為true的情況也很單一 varyByAllParams = (varyByParams.Length == 1) && (varyByParams[0] == "*") 
(3)與_varyByCustom有關(guān),它會(huì)把 context.ApplicationInstance.GetVaryByCustomString(context, cachedVary._varyByCustom)方法返回值追加到key中, 
(4)與_contentEncodings有關(guān),如果 context.Response.GetHttpHeaderContentEncoding()返回的值在_contentEncodings中則追加其返回值。 
注意:如果此Http處理是一個(gè)Post并且request.Form.Count ==0&& _varyByAllParams為rue的時(shí)候海域我們post過來的數(shù)據(jù)有關(guān)。

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 免费av在线网站 | av在线中文 | 欧美日韩中文字幕 | 日韩城人免费 | 欧美日韩综合精品 | 伊人av成人 | 一区二区三区四区在线 | 欧美一区二区三区视频 | 黄色一级大片在线免费看产 | 日韩一区二区三区在线观看 | 日韩av免费在线观看 | 国产日韩精品在线观看 | 在线成人免费 | 国产资源视频在线观看 | 久久精品国产清自在天天线 | 91精品国产乱码久久久久久 | 国产精品自产拍在线观看 | 成人高清视频在线观看 | 久久久www成人免费精品 | 夜夜爽99久久国产综合精品女不卡 | 91麻豆精品国产91久久久资源速度 | 阿v视频在线 | 亚洲免费成人 | 日本视频免费高清一本18 | 久久成人免费视频 | 国产精品去看片 | 成人精品一区亚洲午夜久久久 | 国产日韩一区二区 | 视频在线一区二区 | 涩涩视频在线看 | 国产亚洲精品精品国产亚洲综合 | 国产一区二区三区在线免费 | 亚洲综合一区二区 | av大片网 | 精品日韩一区二区 | 欧美在线亚洲 | 欧美 日韩 成人 | 一区二区三区有限公司 | 在线精品一区二区 | 欧美久久综合 | 国产精品久久久久国产a级 最新国产视频 |