Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between HttpRuntime.Cache and HttpContext.Current.Cache?

Tags:

asp.net

What is the difference between HttpRuntime.Cache and HttpContext.Current.Cache?

like image 218
Tushar Maru Avatar asked May 14 '09 14:05

Tushar Maru


People also ask

Is HttpContext current Cache thread safe?

The HttpContext. Current. Cache object itself is thread safe meaning that storing and reading from it are thread safe but obviously objects that you store inside might not be thread safe.

Where is Httpruntime cache stored?

Cache is stored in web server memory.


2 Answers

I find following detail from http://theengineroom.provoke.co.nz/archive/2007/04/27/caching-using-httpruntime-cache.aspx

For caching I looked into using HttpContext.Current.Cache but after reading other blogs I found that caching using HttpContext uses HttpRuntime.Cache to do the actual caching. The advantage of using HttpRuntime directly is that it is always available, for example, in Console applications and in Unit tests.

Using HttpRuntime.Cache is simple. Objects can be stored in the cache and are indexed by a string. Along with a key and the object to cache the other important parameter is the expiry time. This parameter sets the time before the object is dropped from the cache.

Here is good link for you.

Another good resource.

like image 200
Syed Tayyab Ali Avatar answered Sep 21 '22 08:09

Syed Tayyab Ali


Caching using HttpContext uses HttpRuntime.Cache to do the actual caching. The advantage of using HttpRuntime directly is that it is always available in console applications and in unit tests.

like image 41
Wayne Hartman Avatar answered Sep 21 '22 08:09

Wayne Hartman