HttpContext中的Cache与Items

本文介绍了HttpContext中的Cache与Items。Cache对象用于缓存数据,应用范围是应用程序域,生存期与应用程序相关,有专门的缓存管理特性。Items的作用域是一个独立的Web请求,通过示例展示了其作用域特点,如重定向会产生新的Context。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.HttpContext.Cache
有关缓存,可以参考这篇文章:
http://www.cnblogs.com/abac/archive/2004/02/11/1166.aspx
它提到:
Asp.net中,提供了专门用于缓存数据的Cache对象,它的应用范围是应用程序域。生存期是和应用程序紧密相关的,每当应用程序启动的时候就重新创建Cache对象。它域Application对象的主要区别就是提供了专门用于缓存管理的特性,比如依赖和过期策略。
你可以使用Cache对象和它的属性来实现高级的缓存功能,同时可以利用Asp.net Cache来对客户端输出的响应内容进行缓存。

2.HttpContext.Items
参考文章:http://odetocode.com/Articles/111.aspx
它提到:
First, let’s be clear and state that what you keep in the Items collection will have a very limited scope. Anything you place into the Items collection will only be around for the duration of a single web request, unlike the Session collection, which will keep it’s contents around for each user as long as they continue to make requests. Nevertheless, we will demonstrate several useful techniques with the Items collection in this article.
HttpContext.Items的作用域是一个独立的Web请求。有关它的作用域,它举了个例子:
在页面WebForm1.aspx的Page_Load中加入:
...
Context.Items["WebForm1List"] = list;
Server.Transfer("WebForm2.aspx");

然后在WebForm2.aspx的Page_Load中加入:
ArrayList list = Context.Items["WebForm1List"] as ArrayList;
结果运行正常,但将Server.Transfer换成Response.Redirect就不行了原因是重定向使用了新的HTTP request然后将会有新的Context而此时的Context并不是原先我们在WebForm1.aspx中放有list的Context了。


posted on 2004-06-19 14:25 浙林龙哥 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/huqingyu/archive/2004/06/19/17126.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值