ASP.NET2.0 缓存(Cache)技术介绍

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

自定义控件在前台加入:

<%@ 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();
    }
原文地址:https://www.cnblogs.com/shengel/p/804116.html