Asp.Net2.0使用Cache(简单)

ASP.NET 2.0提供了一些新的用于提升程序性能的技术特性,其中,缓存技术是非常重要的一个特性,它提供了一种非常好的本地数据缓存机制,可以非常容易的定制属于数据缓从,从而有效的提高数据访问的性能。

经试验,觉得自定义控件中加入缓存,从而实现整个页的局部缓存,效果不错。

自定义控件在前台加入:

<%@ OutputCache Duration="60" VaryByParam="none" %>

后台代码:

protected void Page_Load(object sender, EventArgs e)
...{
Label1.Text = DateTime.Now.ToString();

source = (DataView)Cache["SQUARE"];

if (source == null)
...{
conn = new SqlConnection(ConfigurationManager.ConnectionStrings["GoConnectionString"].ConnectionString);
mycmd = new SqlDataAdapter("select * from GUser", conn);

DataSet ds = new DataSet();

mycmd.Fill(ds, "GUser");

source = new DataView(ds.Tables["GUser"]);

Cache["SQUARE"] = source;

}
else
...{

}

GridView1.DataSource = source; 需要请联系我
GridView1.DataBind();
}

posted on 2007-09-26 21:42  leup  阅读(169)  评论(0编辑  收藏  举报

导航