How to make per- http Request cache in ASP.NET 3.5

耗尽温柔 提交于 2019-12-06 16:48:03

问题


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?


回答1:


We have used HttpContext.Current.Items collection to do RequestScope caching. It works well.




回答2:


just to clarify what ggonsalv was referring to

http://msdn.microsoft.com/en-us/library/system.web.httpcontext.items.aspx

HttpContext.Items["key"] = value;

UPDATE: the mvc specific version

http://msdn.microsoft.com/en-us/library/system.web.mvc.controller.httpcontext(v=VS.100).aspx




回答3:


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"



来源:https://stackoverflow.com/questions/2724058/how-to-make-per-http-request-cache-in-asp-net-3-5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!