当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > 新手入门之ASP.NET2.0中的缓存技术解析

ASP.NET
asp.net 使用Silverlight操作ASPNETDB数据库
ASP.NET 前后台调用方法
ASP.NET中等安全模式的一些经验分享
asp.net 打印控件使用方法
网站开发技术:ASP.NET 2.0搭建网站
ASP.NET实例教程:创建数据透视表
ASP.NET 4进行SEO优化提高网站排名和权重
ASP.NET实例教程:订阅 GeoRSS 订阅源
ASP.NET页面间数据传递的9种方法
ASP.NET教程:网页表单多个按钮完成不同功能
Asp.net的服务器推技术 (Server Push)
asp.net 无刷新附件上传实现方法
ASP.NET 定制简单的错误处理页面实现代码
c# 在WebBrowser中用SendMessage模拟鼠标点击
asp.net 表单验证新思路
.NET从优酷专辑中采集所有视频及信息(VB.NET代码)
VS2005 水晶报表在时部署时遇到的问题
ASP.NET 输出图片简单代码
一天精通asp.net的学习经验小结
DataGridView中绑定DataTable数据及相关操作实现代码

新手入门之ASP.NET2.0中的缓存技术解析


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-08-14   浏览: 70 ::
收藏到网摘: n/a

ASP.NET2.0提供如下缓存方式:

Output Caching

Fragment Caching

Data Cache

SQL Cache

Cache Configuration

1. Output Caching:

当一个网页被频繁访问时,我们可以把把整个网页缓存起来提高效率,当用户在此访问时,被格式化好的HTML被直接送到客户端。

2. 参数缓存:

根据用户的请求来生成页面,用户的请求只有有限的几种组合,我们根据参数该表缓存内容。

<%@ OutputCache Duration="120" VaryByParam="state" %>

<%--<a href="Default.aspx?state=CA"></a>--%>

3. 硬盘缓存:

默认情况下Output Cache会缓存到硬盘上,我们可通过修改diskcacheenable的属性设置其是否缓存,还可以通过在web config里配置缓存文件的大小。

4. 页面碎片缓存:

页面上部分内容根据请求动态更新,大部分能容被缓存。(如果多个控件需要缓存,可做成一个用户控件)

<%@OutputCache Duration="120" VaryByControl="ControlID" %>

<center><img src="http://myarticle.enet.com.cn/images/2007/1213/1197510156064.jpg" border="0" alt="新手入门 ASP.NET2.0缓存技术"/></center>

5. Cache Data :

建议打开硬盘缓存,缓存时间设的稍长一点,因为IO的开销

DataSet ds=new DataSet();

ds = Cache["restaurant"];

if (ds == null)

{

ds = resDataSet;

Cache["restaurant"] = ds;

}

6. SQL Dependency

配置数据库服务器的sql缓存,然后在页面引用

<center><img src="http://myarticle.enet.com.cn/images/2007/1213/1197510159540.jpg" border="0" alt="新手入门 ASP.NET2.0缓存技术"/></center>

7. Cache Configuration (减少重复定义)

a .web.config定义

<center><img src="http://myarticle.enet.com.cn/images/2007/1213/1197510164294.jpg" border="0" alt="新手入门 ASP.NET2.0缓存技术"/></center>

b. 页面调用

<%@ OutputCache CacheProfile="CacheFor60Seconds" VaryByParam="name" %>
<table width="90%" border="0" cellpadding="0" cellspacing="0" align="center">
<tr> <td><b>热门推荐</b>:</td>
<td><a href="http://www.enet.com.cn/article/2007/1210/A20071210942740.shtml" target="_blank"><font size=2 color=red>无敌命令 删除不能删除的文件
</font></a></td>
<td><a href="http://www.enet.com.cn/article/2007/1211/A20071211943925.shtml" target="_blank"><font size=2 color=red>不怕被攻击 Windows防黑技巧七招</font></a></td>
</tr></table>