Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between ASP.NET caches

Tags:

c#

.net

caching

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?

like image 670
thaRyy Avatar asked Jan 23 '26 03:01

thaRyy


1 Answers

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.

like image 60
Suhaib Janjua Avatar answered Jan 25 '26 17:01

Suhaib Janjua



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!