1、Output caching:缓存整个网页
2、Fragment caching:部分缓存
3、Data Caching:数据缓存
4、Sql Cache:监视数据库改变
5、Cache Configuration
1、Output caching:缓存整个网页
(1) 普通的Output caching
<%@OutputCache Duration="60" VaryByParam="none" %>:时间为60秒,不任何接受参数
<%@OutputCache Duration="60" VaryByParam="state" %>:时间为60秒,根据state的参数不同,进行不同的缓存
(2) 硬盘缓存
<%@OutputCache Duration="3600" VaryByParam="none" DiskCacheable="true"%>:硬盘缓存,把生命期设置得大一点
web.config
//2M
<caching>
<outputCache>
<diskCache enabled="true" maxSizePerApp="2" />
</outputCache>
</caching>
(3) 回调缓存
把Substitution的MethodName设置需要的函数
(4) Windows API 定制
Response.Cache.SetExpires( Now.AddSeconds(60));
Response.Cache.SetCacheability( HttpCacheability.Public );
2、Fragment caching:部分缓存
在需要缓存的控件中加上<%@OutputCache Duration="60" VaryByParam="none" %>,整个页面不加。
3、Data Caching:数据缓存
Cache("MyDataSet");
思路判断是否已经有缓存了,如果有了就直接取出来;如果没有就赋值。
4、Sql Cache
aspnet_regsql.exe
-s:注册的服务器
-e:使用Window授权模式
-d: datebase名字
-ed:生效
aspnet_regsql.exe -S "./SQLExpress" -E -d "pubs" -ed
aspnet_regsql.exe -S "./SQLExpress" -E -d "pubs" -et -t "authors"
<%@OutputCache Duration="999999" SqlDependency="Pubs:Authors" VaryByParam="none" %>
5、Cache Configuration
web.config
<caching>
<outputCacheSettings>
<outputCacheProfiles>
<add name="CacheFor60Seconds" duration="60" />
</outputCacheProfiles>
</outputCacheSettings>
</caching>
在引用的地方
<%@ OutputCache CacheProfile="CacheFor60Seconds" VaryByParam="name" %>