| 概述1.意義 把數(shù)據(jù)放到Cache中,在指定的時(shí)間內(nèi),可以直接從Cache中獲取,避免對數(shù)據(jù)庫等的壓力。 2.做法 設(shè)置: HttpRuntime.Cache.Insert(CacheKey, objObject,null,absoluteExpiration,slidingExpiration); 讀?。?/FONT> HttpRuntime.Cache[“name”] Demoprotected void Page_Load(object sender, EventArgs e) { //Cache是全局共享的 DataTable dt = (DataTable)HttpRuntime.Cache["persons"]; //如果Cache中沒有,再去數(shù)據(jù)庫中查詢 //這樣可以降低數(shù)據(jù)庫服務(wù)器的壓力  if (dt == null) { dt = SqlHelper.ExecuteQuery("select * from T_Persons"); //存儲(chǔ)緩存,30秒后過期 HttpRuntime.Cache.Insert("persons", dt, null, DateTime.Now.AddSeconds(30), TimeSpan.Zero); } Repeater1.DataSource = dt; Repeater1.DataBind(); } | 
|  |