Asp.Net2.0学习笔记(四):缓存的使用

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" %>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值