现在,让我们在Global类中建立缓存机制,这样我们不需要在任何页面中编写特定的代码
public class Global : System.Web.HttpApplication
{
Cache _cache =null;
public static bool blnReflash = false;
public const string ConnStr = "server=localhost;database=Northwind;uid=sa;pwd=";
public const string strSQL = "SELECT EmployeeID, lastname, firstname FROM Employees";
protected void Application_Start(Object sender, EventArgs e)
{
_cache = Context.Cache;
RefreshCahe(null,null,0);
}
protected void Session_Start(Object sender, EventArgs e)
{
if(HttpContext.Current.Cache["Employees"]==null)
RefreshCache(null,null,0);
}
static void RefreshCache(string key,object item,CacheItemRemoveReason reason)
{
SqlDataAdapter adapter = new SqlDataAdapter(strSQL,ConnStr);
DataSet ds = new DataSet();
adapter.Fill(ds,"Employees");
CacheItemRemovedCallback onRemove = new CacheItemRemovedCallback(RefreshCache);
}
希望本文所述对大家的asp.net程序设计有所帮助。








