• 缓存的运用


    using System.Diagnostics;
    using System.Data;
    using System.Data.SqlClient;

    public partial class Default3 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            //using System.Diagnostics
            Stopwatch sw = new Stopwatch();
            sw.Start();
            for (int i = 0; i < 100; i++)
            {
                Response.Write(i.ToString()+"<br/>");
            }
            Response.Write("--------------------------------------------");
            Response.Write(sw.ElapsedTicks);
        }

        public DataSet Dbind()
        {
            DataSet ds = new DataSet();
            using (SqlConnection con = new SqlConnection("server=.;database=a;uid=sa;pwd=123456"))
            {
                con.Open();
                using (SqlDataAdapter cmd = new SqlDataAdapter("select * from a", con))
                {
                    cmd.Fill(ds);
                }
            }
            return ds;
        }

        //从数据库读出来
        protected void Button3_Click(object sender, EventArgs e)
        {
            Stopwatch sw = new Stopwatch();
            sw.Start();
            DataSet ds= Dbind();
            Response.Write(string.Format("查询结果:{0}<br/>", ds.Tables[0].Rows[300000][0]));
            Response.Write(string.Format("耗费时间:{0}<br/>", sw.ElapsedTicks));   //时间 10978159

        }

        //从缓存读出来
        protected void Button4_Click(object sender, EventArgs e)
        {
            DataSet ds;
            Stopwatch sw = new Stopwatch();
            sw.Start();
            if (Cache["Data"] != null)
            {
                ds = Cache["Data"] as DataSet;
            }
            else
            {
                ds = Dbind();
            }
            Response.Write(string.Format("查询结果:{0}<br/>", ds.Tables[0].Rows[300000][0])); 
            Response.Write(string.Format("耗费时间:{0}<br/>", sw.ElapsedTicks));   //时间 60
        }

        //写入缓存
        protected void Button2_Click(object sender, EventArgs e)
        {
            DataSet ds = Dbind();
            Cache.Insert("Data", ds);  
        }

        //删除缓存
        protected void Button5_Click(object sender, EventArgs e)
        {
            Cache.Remove("Data");
        }
    }

    http://www.cnblogs.com/luluping/archive/2009/09/13/1565732.html

  • 相关阅读:
    紫外传感器波长
    常见设备功耗
    点型感温火灾探测器研发思路
    C#使用Linq to XML进行XPath查询
    题解 最大获利
    题解 走迷宫
    2020-11-16 考试题解
    题解 最小生成树
    题解 「BZOJ4919 Lydsy1706月赛」大根堆
    题解 2020.10.24 考试 T4 模板
  • 原文地址:https://www.cnblogs.com/wujy/p/2272052.html
Copyright © 2020-2023  润新知