缓存---页面缓存
![](http://hi.csdn.net/attachment/201010/28/0_1288273145I83p.gif)
添加页面缓存 <%@ OutputCache Duration="5" VaryByParam="none" %>
运行成功后显示如下:
![](http://hi.csdn.net/attachment/201010/28/0_12882732628AZ9.gif)
每隔5秒时间进行更新。
--------------------------------------------------
下面把VaryByParm的none值该为Id ,同时添加一个textbox控制
前台代码如下:
![](http://hi.csdn.net/attachment/201010/28/0_1288273356wy01.gif)
后台代码对应修改如下
![](http://hi.csdn.net/attachment/201010/28/0_1288273442pCAu.gif)
其中Response.Redirect("PageCache.aspx?id="+TextBox1.Text);表示每次点击后都返回当前Id
效果如下:
![](http://hi.csdn.net/attachment/201010/28/0_1288273538764U.gif)
当文本框输入3时点 Update按钮 当前时间是 22秒,
此时输入4 当前时间是24秒,由于我们根据的是VaryByParam为Id,同时Duration时间为5秒,所以当我们再次输入3时,由于未超过5秒所以当前显示的时间仍为22秒。
-------------------------------------------------------
下面引发的一个问题就是如何对多个控件进行缓存呢?
其实很简单 VaryByParam="Id;name;type..." 用分号隔开即可。
------------------------------------------------
下面讲解的是如何在Web.Config中进行配置页面缓存
![](http://hi.csdn.net/attachment/201010/28/0_1288273650XxC9.gif)
首先在System.web下写入如下代码
<caching>
<outputCache enableOutputCache="true" />
<outputCacheSettings>
<outputCacheProfiles>
<add name="myPageCache" duration="10" enabled="true" />
</outputCacheProfiles>
<outputCacheSettings>
</cahing>
对应的如何在前台页面中使用呢?
![](http://hi.csdn.net/attachment/201010/28/0_1288273745Zp3n.gif)
添加为CacheProfile="myPageCache" 即可。
这样就方便了统一的修改和配置。
---------------------------------------------
页面缓存至此讲解完毕。
下面讲解 2 文件缓存依赖