gpt4 book ai didi

asp.net - HttpRuntime缓存和HttpContext缓存之间有什么区别?

转载 作者:行者123 更新时间:2023-12-03 12:54:07 24 4
gpt4 key购买 nike

我知道有一个非常相似的问题here,但我希望得到更好的解释。如果HttpContext确实在后台使用HttpRuntime.Cache,为什么还要使用HttpContext.Cache而不是HttpRuntime.Cache?

在文章Simulate a Windows Service using ASP.NET to run scheduled jobs中,Omar使用HttpContext来存储他的缓存项,但是当Jeff Atwood实施here时,他选择使用HttpRuntime。显然,在这种特殊情况下,这是有道理的,因为您不必执行Web请求就可以将缓存项添加回HttpContext中。

但是,我正在寻找一些有关何时使用一个相对于另一个的好的指导。

最佳答案

最后确实是相同的缓存,有时只有HttpContext.Current可以为null(当不在Web上下文中或在Web上下文中但尚未构造时)。始终使用HttpRuntime.Cache是安全的。

关于asp.net - HttpRuntime缓存和HttpContext缓存之间有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1108990/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com