zoukankan      html  css  js  c++  java
  • 缓存依赖注意

    1.表名必须要加dbo.,否则会不缓存每次都会读数据库。

    2.如下语句要写在定义Dataset的前面,否则会更新了数据表,缓存还是没失效,显示的旧数据。

    System.Web.Caching.SqlCacheDependency sqlcache = new System.Web.Caching.SqlCacheDependency(commad);

    protected void Page_Load(object sender, EventArgs e)
        {
            StringBuilder strSql = new StringBuilder();
            //strSql.Append("SELECT [id] ,[value] FROM [dbo].[Test]");


            strSql.Append("select ");

            strSql.Append(" Name,LoginID,PassWord,status,MobileNo,ItvNo ");
            strSql.Append(" FROM dbo.Member ");


            this.data.DataSource = GetMember(strSql.ToString());// ExecuteAndCache(strSql.ToString());//
            this.data.DataBind();
        }


        private DataTable GetMember(string strSql)
        {

            //string key = strSql;// "T1";

            if (HttpRuntime.Cache[strSql] == null)
            {
             
                using (SqlConnection sqlconn = new SqlConnection(SqlHelp.conn))
                {

                    using (SqlCommand commad = new SqlCommand())
                    {
                        System.Web.Caching.SqlCacheDependency sqlcache = new System.Web.Caching.SqlCacheDependency(commad);
                        commad.CommandType = CommandType.Text;
                        commad.CommandText = strSql;                   
                        commad.Connection = sqlconn;
                       

                        DataSet ds = new DataSet();                 

                        new SqlDataAdapter(commad).Fill(ds);
                       
                        HttpRuntime.Cache.Insert(strSql, ds, sqlcache);//添加到缓存中
                    }

                }


            }

            DataSet tds = HttpRuntime.Cache[strSql] as DataSet;
            if (tds != null)
                return tds.Tables[0];
            else
                return null;
        }

    alter database [Test] set enable_broker

    select databasepropertyex('[Test]','IsBrokerEnabled')

  • 相关阅读:
    在jenkins中新建节点,启动方式中没有“通过java web启动”
    在jenkins上执行web自动化脚本出现cannot find Chrome binary
    修改禅道的默认端口
    jmeter修改字体大小
    电脑中安装了两个版本的jdk,后装的会把第一个覆盖掉
    各种浏览器的驱动
    js中的null和undefined总结
    关于 es6的 let 特性在 for 循环结构 的个人理解
    ajax五,jsonp跨域的本质
    ajax四,封装ajax并优化
  • 原文地址:https://www.cnblogs.com/antyi/p/2631866.html
Copyright © 2011-2022 走看看