What is the difference between the HttpContext
class's Cache
and Items
properties?
From the MSDN Documentation:
Cache
Gets the Cache object for the current application domain.Items
Gets a key/value collection that can be used to organize and share data between an IHttpModule interface and an IHttpHandler interface during an HTTP request.
I don't really understand what that documentation is trying to explain.
While working on ASP.NET web applications, I have often used Items
for per-request caching of data so that multiple user controls don't end up looking up the same data from the database. This is described in this article.
Today though, I came across usages of the Cache
property for, what looked like, per-request caching. I tried to understand the difference but couldn't find any good documentation comparing these two. So I would like to know...
What is the difference between HttpContext's Cache and Items properties? Please try to elaborate with examples of why you would choose to use one over the other in different real-world scenarios.