新手入门之ASP.NET2.0中的缓存技术解析
点击次数:25 次 发布日期:2008-11-21 22:16:31 作者:源代码网
|
源代码网推荐源代码网整理以下ASP.NET2.0提供如下缓存方式:
源代码网整理以下Output Caching
源代码网整理以下Fragment Caching
源代码网整理以下Data Cache
源代码网整理以下SQL Cache
源代码网整理以下Cache Configuration
源代码网整理以下1. Output Caching:
源代码网整理以下当一个网页被频繁访问时,我们可以把把整个网页缓存起来提高效率,当用户在此访问时,被格式化好的HTML被直接送到客户端。
源代码网整理以下
| <%@ OutputCache Duration="120" VaryByParam="none" %> |
源代码网整理以下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>
|
源代码网供稿. |