最近在对程序进行性能上的优化和改进。很多地方都要修改。于是想做一些测试。代码如下:
 protected void Button2_Click(object sender, EventArgs e)
        {
            HttpContext.Current.Response.Write("开始时间:"+DateTime.Now.ToFileTime() + "<br/>");
            if (CacheHelper.GetCache("connectionString") == null)
            {
                string conn = ConfigurationManager.ConnectionStrings["connString"].ConnectionString + HttpContext.Current.Server.MapPath(ConfigurationManager.ConnectionStrings["dataPath"].ConnectionString);
                CacheDependency fileDependency = new CacheDependency(HttpContext.Current.Server.MapPath("Web.config"));
                CacheHelper.AddCache("connectionString", conn, fileDependency);
            }
            string connectionString = CacheHelper.GetCache("connectionString").ToString();
            HttpContext.Current.Response.Write("结束时间:"+DateTime.Now.ToFileTime() + "<br/>");
        }我的目的是将数据库连接字符串缓存起来。避免同时请求数过多不断读取web.config文件。
但输出的值很奇怪。不论是第一次执行还是后续执行(即不论连接字符串是否缓存),开始时间和结束时间都相同。
是我测试方法有问题还是其它原因。不可能一点时间也不耗啊!!!