thaRyy
thaRyy

Reputation: 31

Difference between ASP.NET caches

What's the difference between:

  1. HttpRuntime.Cache["key"]
  2. HttpContext.Current.Cache["key"]
  3. HttpContext.Current.Application["key"]

are there any major differences between these memories?

Upvotes: 3

Views: 105

Answers (1)

Suhaib Janjua
Suhaib Janjua

Reputation: 3572

HttpContext.Current.Cache and HttpRuntime.Cache are the same, the context cache prop just returns the runtime Cache. HttpRuntime and HttpContext just return handles to this object.

HttpRuntime.Cache is recommended but likely won't make a difference in most applications.

HttpContext.Current.Application is not a cache, its a global named value collection. if you add an object to Application it will stay until a an appdomain recycle. If you put an object in cache, it not guaranteed to be there when you fetch it. The cache is free to throw it away if the cache get too large, or the object has fetched often enough.

Upvotes: 1

Related Questions