標籤:tostring pen ret pre class 擷取 時間 highlight protect
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;public partial class Default2 : System.Web.UI.Page{ protected void Page_Load(object sender, EventArgs e) { string CacheKey = "cachetest"; object objModel = GetCache(CacheKey);//從緩衝中擷取 if (objModel == null)//緩衝裡沒有 { objModel = DateTime.Now;//把目前時間進行緩衝 if (objModel != null) { System.Web.Caching.CacheDependency dep=new System.Web.Caching.CacheDependency("C:\\test.txt"); SetCache(CacheKey, objModel, dep);//寫入緩衝 } } Label1.Text = objModel.ToString(); } public static object GetCache(string CacheKey) { System.Web.Caching.Cache objCache = HttpRuntime.Cache; return objCache[CacheKey]; } public static void SetCache(string CacheKey, object objObject,System.Web.Caching.CacheDependency dep) { System.Web.Caching.Cache objCache = HttpRuntime.Cache; objCache.Insert(CacheKey, objObject,dep,System.Web.Caching.Cache.NoAbsoluteExpiration, System.Web.Caching.Cache.NoSlidingExpiration, System.Web.Caching.CacheItemPriority.Default,null ); }}
。net 檔案依賴緩衝