1.outputcache
<%@ outputcache Duration="60" VaryByParam="none" %>
2.根据参数缓存
<%@ outputcache Duration="60" VaryByParam="state" %> state为返回参数名
3.disk outputcache
<%@ outputcache Duration="60" VaryByParam="none" DiskCacheable="true" %>
web.config
<caching>
<outputCache>
<diskCache enabled="true" maxSizePerApp="2" />
</outputCache>
</caching>
4.回调缓存 缓存部分页面
<asp:Substitution /> 来实现
5.Page Fragment Caching
用于缓存用户控件,在页面中,通过指定返回参数,来决定控件被缓存的部分
把控件放在ascx,把ascx页面设为缓存
6.datacache 实行性能比outputcache要好
DataView Source=new DataView();
Source=Cache("MyDataSet");
7.sql Caching
配置数据库连接池,只有当数据库数据被改变的时候,缓存才会改变。
aspnet_regsql.exe -S ".\SQLExpress" -E -d "pubs" -ed
-S ".\SQLExpress" 服务器名称 -E 连接方式 -d "pubs" 数据库名称 -ed 启用数据库 //sql2005不需要配置
aspnet_regsql.exe -S".\SQLExpress" -E -d "pubs" -t "authors" -et
-S ".\SQLExpress" 服务器名称 -E 连接方式 -d "pubs" 数据库名称 -t "authors" 表名称 -et启用表监视 //sql2005不需要配置
web.config准备:
<system.web>
<caching>
<sqlCacheDependency enabled="true" pollTime="5000">
<databases>
<add name="Northwind" connectionStringName="Northwind" />
</databases>
</sqlCacheDependency>
</caching>
</system.web>
<%@ outputcache Duration="9999999" VaryByParam="none" SqlDependency="Pubs Authors" %>