Page.Cache. HttpContext.Cache. HttpRuntime.Cache. Hsahtable有什么區別,怎樣用
轉自:http://zwjy.gjjblog.com/archives/3683/HttpContext.Cache,HttpRuntime.Cache,用法上沒有區別,就是使用范圍不同.
HttpContext.Cache是基于上下文,對同一個用戶起做用,如果換了一個訪問,那么這個CACHE就不起做用了.
HttpRuntime.Cache是全局的,對任務人都有做,只要有內容,任務用戶都可以訪問.


















Page.Cache實際上是訪問其它CACHE的接口.可以通過Page.Cache來訪問HttpContext.Cache,HttpRuntime.Cache里面的東西.
還有另外一種保存Cache方式是,使用Hashtable等來保存,值的一說的是這種Cache也是全局 ,而且是不可過期的 ,我想這是與 HttpRuntime.Cache的一個區別吧.至于安全性能方面我還沒有去驗證.Hashtable保存方式比較特別,就是NEW的時候要使用同步關健字.
?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) 評論(0) 編輯 收藏