最近在对程序进行性能上的优化和改进。很多地方都要修改。于是想做一些测试。代码如下:
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文件。
但输出的值很奇怪。不论是第一次执行还是后续执行(即不论连接字符串是否缓存),开始时间和结束时间都相同。
是我测试方法有问题还是其它原因。不可能一点时间也不耗啊!!!
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文件。
但输出的值很奇怪。不论是第一次执行还是后续执行(即不论连接字符串是否缓存),开始时间和结束时间都相同。
是我测试方法有问题还是其它原因。不可能一点时间也不耗啊!!!
解决方案 »
- 给读取的cookie指定gb2312编码格式
- jquery 操作ul li
- iframe javascript:location.replace(url)路径问题
- 关于控件的拖动
- 為什麼我用代碼動態產生的gridview導出execl沒有格線呢
- 请教,想做一个类似 配置我感兴趣的社区 的页面
- ASP.NET 用VB.NET编写好 还是用 C#编写好 还是两个综合,还是有侧重
- 用speech sdk写的语音aspx页面,客户端最少安装什么能实现语音识别。
- 做到有限的安全,让中继只对特定的IP开放。谢谢。
- 如何實現查詢功能與打印報表功能
- 求纯HTML表单元素 转 服务器控件的工具。
- gridData的RowCommand中的linkbutton重定向问题
Web访问,无时不刻在读取服务端文件,难道所有文件都得缓存?
下一步准备继续缓存反射工厂实体。呵呵