通常一個系統會用到Caching Data的機制
不外乎有幾個共通點

一、多人即時的查詢、交易系統
二、需要在快速的時間將資料反應在前端
三、被查詢的資料變動性不高

當系統符合這個條件時,有些資料最好把他Cache起來
當然Cache的資料不能太多,否則造成反效果...

.net從1.1開始就提供了Cache的機制

這是個很棒的機制,當然還是有其他方法可以完成
不過.net的快取機制提供了很多存取的方法
讓開發的人有更多的彈性(例如CallBack機制、和時間限制)

1.將資料寫入快取
HttpContext.Current.Cache.Insert("user_name", "thomas")
HttpContext.Current.Cache.Insert("user_data", user_datatable)

如果是在一般的Web From裏面就不用加HttpContext.Current
像這樣Cache.Insert("user_name", "thomas")

2.移除快取資料
HttpContext.Current.Cache.Remove("user_name")

3.取得快取資料
CType(HttpContext.Current.Cache("user_name"), String)
CType(HttpContext.Current.Cache("user_data"), DataTable)





arrow
arrow
    全站熱搜

    湯瑪的吳 發表在 痞客邦 留言(0) 人氣()