Page.Cache. HttpContext.Cache. HttpRuntime.Cache. Hsahtable有什么區(qū)別,怎樣用
轉(zhuǎn)自:http://zwjy.gjjblog.com/archives/3683/HttpContext.Cache,HttpRuntime.Cache,用法上沒(méi)有區(qū)別,就是使用范圍不同.
HttpContext.Cache是基于上下文,對(duì)同一個(gè)用戶(hù)起做用,如果換了一個(gè)訪問(wèn),那么這個(gè)CACHE就不起做用了.
HttpRuntime.Cache是全局的,對(duì)任務(wù)人都有做,只要有內(nèi)容,任務(wù)用戶(hù)都可以訪問(wèn).


















Page.Cache實(shí)際上是訪問(wèn)其它CACHE的接口.可以通過(guò)Page.Cache來(lái)訪問(wèn)HttpContext.Cache,HttpRuntime.Cache里面的東西.
還有另外一種保存Cache方式是,使用Hashtable等來(lái)保存,值的一說(shuō)的是這種Cache也是全局 ,而且是不可過(guò)期的 ,我想這是與 HttpRuntime.Cache的一個(gè)區(qū)別吧.至于安全性能方面我還沒(méi)有去驗(yàn)證.Hashtable保存方式比較特別,就是NEW的時(shí)候要使用同步關(guān)健字.
?1
public?class?hashcache
?2
????{
?3
???????private?static?Hashtable?parmCache?=?Hashtable.Synchronized(new?Hashtable());
?4
?5
????????public?static?void?CacheParameters(string?cacheKey,?string?cmdParms)?
?6
????????{
?7
????????????parmCache[cacheKey]?=?cmdParms;
?8
????????}
?9
10
????????public?static?string?GetCachedParameters(string?cacheKey)?
11
????????{
12
????????????return?(string)parmCache[cacheKey];
13
????????}
14
????}

?2


?3

?4

?5

?6


?7

?8

?9

10

11


12

13

14

posted on 2009-01-13 20:20 picture talk 閱讀(645) 評(píng)論(0) 編輯 收藏