asp.net Cache的应用
2010-08-02 16:06
357 查看
一、页输出缓存
1、页面输出缓存的几种形式
①在.aspx文件中添加指令
<%@ OutputCache Duration="60" VaryByParam="None" >
②还可在配置文件里配置缓存名称,然后在页面调用配置文件的缓存名称
步骤1、在配置文件中首先增加caching节
代码protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { DataTable dt = HttpContext.Current.Cache["dt"] as DataTable; if (dt == null) { string connString = ConfigurationManager.ConnectionStrings["b2cshop"].ToString(); using (SqlConnection conn = new SqlConnection(connString)) { conn.Open(); SqlCommand cmd = new SqlCommand("select id,username,score from dbo.test", conn); SqlCacheDependency scd= new SqlCacheDependency(cmd); SqlDataAdapter sda = new SqlDataAdapter(cmd); dt = new DataTable(); sda.Fill(dt); HttpContext.Current.Cache.Insert("dt", dt, scd); } } GridView1.DataSource = dt; GridView1.DataBind(); } }
cache应用源码下载地址
http://files.cnblogs.com/alphacn/DoNetCache.rar
相关文章推荐
- ASP.NET缓存Cache应用简单学习
- 详情ASP.NET状态管理缓存Cache应用(学习)
- ASP.NET缓存Cache的应用-提高数据库读取速度
- asp.net mvc Partial OutputCache 在SpaceBuilder中的应用实践
- asp.net 应用数据缓存 -- Cache对象使用
- asp.net mvc Partial OutputCache 在SpaceBuilder中的应用实践
- ASP.NET缓存Cache的应用-提高数据库读取速度
- ASP.NET Cache简单应用一例
- ASP.NET缓存Cache的应用-提高数据库读取速度
- ASP.NET 2.0防止同一用户同时登陆(cache的应用)
- ASP.NET缓存Cache的应用-提高数据库读取速度
- ExtAspNet应用技巧(十三) - 后台主页面(IFrame框架)
- asp.net网站中CrystalReport的简单应用
- ASP.NET中主题的创建和应用
- 关于 Ajax 在ASP.NET 中应用的小例子
- asp.net 皮肤功能的应用
- 使用ASP.NET 5开发AngularJS应用
- ASP.NET+WCF 应用
- Partial Page Output Caching in ASP.NET MVC 3 - OutputCache Attribute
- ASP.net随机数应用实例