加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net – HttpContext的Cache和Items Properties有什么区别?

发布时间:2020-12-15 20:52:15 所属栏目:asp.Net 来源:网络整理
导读:HttpContext 级 Cache 和 Items 属性有什么区别? 从MSDN文档: Cache Gets the Cache object for the current application domain. Items Gets a key/value collection that can be used to organize and share data between an IHttpModule interface and
HttpContextCacheItems属性有什么区别?

从MSDN文档:

Cache
Gets the Cache object for the current application domain.

Items
Gets a key/value collection that can be used to organize and share data between an IHttpModule interface and an IHttpHandler interface during an HTTP request.

我真的不明白该文档试图解释什么.

在处理ASP.NET Web应用程序时,我经常使用Items来按请求缓存数据,这样多个用户控件最终不会从数据库中查找相同的数据.这在this article中描述.

今天,我遇到了Cache属性的用法,看起来像每个请求缓存.我试图理解差异,但找不到比较这两者的任何好的文件.所以我想知道……

HttpContext的Cache和Items属性有什么区别?请尝试详细说明为什么在不同的真实场景中选择使用其中一个的示例.

解决方法

项目是按请求进行的,因此它仅适用于给定HTTP请求的给定用户.缓存在存储器中存储一段时间,并且它不依赖于特定用户.因此,可以跨多个请求跨多个用户共享缓存,但每个请求的每个用户都是Items.

这取决于您希望数据存在多长时间.我使用Items来存储EF中的ObjectContext或DbContext之类的东西,我只希望为该请求共享它.但是所有用户将在许多请求中使用的参考表数据,因此缓存会更好.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读