• 缓存的运用


    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

  • 相关阅读:
    Lock接口与等待唤醒机制
    线程同步(线程安全处理Synchronized)与死锁
    关于线程安全的例子(电影票出售)
    线程池
    多线程
    commons-IO工具包
    打印流
    关于web的安全问题
    防止手机页面软键盘调出时布局被挤压
    css3新特性归总笔记
  • 原文地址:https://www.cnblogs.com/wujy/p/2272052.html
Copyright © 2020-2023  润新知