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?
In-Memory Cache is used for when you want to implement cache in a single process. When the process dies, the cache dies with it. If you're running the same process on several servers, you will have a separate cache for each server. Persistent in-process Cache is when you back up your cache outside of process memory.
This can be done by creating user controls for each area that needs to be cached. After you create user controls for the cached fragments of the web page, you can set their @ OutputCache attributes as if they were a regular web page. This process is referred to as fragment or partial page caching.
For output caching, an OutputCache directive can be added at the top of the . aspx page , specifying the duration (in seconds) that the page should be cached. All the attributes that we specify in an OutputCache directive are used to populate an instance of the System.
ASP.NET provides caching of web pages through Page Output Caching. A page is enabled for caching using the @OutputCache directive. This directive is written at the top of the page which is to be cached. The code below shows the code in the hold to cache a web page for 60 seconds.
We have used HttpContext.Current.Items collection to do RequestScope caching. It works well.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With