什么是的httpRuntime缓存和缓存的HttpContext之间的区别? [英] What's the difference between the HttpRuntime Cache and the HttpContext Cache?

查看:307
本文介绍了什么是的httpRuntime缓存和缓存的HttpContext之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道有一个非常类似的问题<一href=\"http://stackoverflow.com/questions/863654/difference-b-w-httpruntime-cache-vs-httpcontext-current-cache\">here但我希望能获得一份更好explination。为什么我会永远使用HttpContext.Cache代替HttpRuntime.Cache如果真的HttpContext的使用HttpRuntime.Cache幕后?

I know there is a very similar question here but I was hoping to get a better explination. Why would I ever use HttpContext.Cache instead of HttpRuntime.Cache if the HttpContext really uses the HttpRuntime.Cache behind the scenes?

在文章使用ASP.NET运行调度作业奥马尔模拟Windows服务使用的HttpContext来存储自己的缓存项,但是当杰夫阿特伍德实现了它href=\"http://blog.stackoverflow.com/2008/07/easy-background-tasks-in-aspnet/\">这里他选择使用的httpRuntime来代替。显然,在这种特定情况下它使自从你不必做一个网络请求中添加缓存项回到HttpContext的感觉。

In the article Simulate a Windows Service using ASP.NET to run scheduled jobs Omar uses the HttpContext to store his cache items, but when Jeff Atwood Implemented it here he chose to use the HttpRuntime instead. Obviously in this particular situation it makes sense since since you don't have to do a web request to add the cache item back into the HttpContext.

但我在寻找一些好的指针何时使用一个与其他。

However I'm looking for some good pointers as to when to use one versus the other.

推荐答案

这真的是在年底相同的缓存,仅 HttpContext.Current 有时为空(当不是在网络的背景下,或在web上下文但尚未构成)。你会是安全的,总是用 HttpRuntime.Cache

It really is the same cache at the end, only HttpContext.Current can sometimes be null (when not in a web context, or in a web context but not yet constructed). You'd be safe to always use HttpRuntime.Cache.

这篇关于什么是的httpRuntime缓存和缓存的HttpContext之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆