如何在 ASP.NET 3.5 中对每个 http 请求进行缓存
我们使用 ASP.NET 3.5(基于控件的方法),并且只需要特定于一个 http 请求的存储。
使用会话 id 中的键的线程特定缓存将不起作用,因为线程应该被池化,因此我有机会在缓存中获得来自某些先前请求的数据,这在我的情况下是不可取的。我总是需要为整个请求中的每个请求提供全新的存储空间。
有什么想法如何在 ASP.NET 3.5 中做到这一点吗?
We using ASP.NET 3.5 (Controls-based approach) and need to have storage specific for one http request only.
Thread-specific cache with keys from session id won't work because threads are supposed to be pooled and therefore I have a chance to have data from some previous request in cache, which is undesirable in my case. I always need to have brand new storage for each request available through whole request.
Any ideas how to do it in ASP.NET 3.5?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我们使用了 HttpContext。 Current.Items集合做RequestScope缓存。效果很好。
We have used HttpContext.Current.Items collection to do RequestScope caching. It works well.
只是为了澄清 ggonsalv 所指的内容
http://msdn .microsoft.com/en-us/library/system.web.httpcontext.items.aspx
更新:mvc特定版本
http://msdn.microsoft.com/en-us/library/system.web.mvc.controller。 httpcontext(v=VS.100).aspx
just to clarify what ggonsalv was referring to
http://msdn.microsoft.com/en-us/library/system.web.httpcontext.items.aspx
UPDATE: the mvc specific version
http://msdn.microsoft.com/en-us/library/system.web.mvc.controller.httpcontext(v=VS.100).aspx
使用 Context 集合怎么样?这允许在所有控件之间共享数据,但仅持续请求。
像这样使用它
context.Items("base_url") = "default.aspx"
How about using the Context collection. This allows data to be shared between all your controls but only lasts for the request.
Use it like this
context.Items("base_url") = "default.aspx"